ANKIT P. answered 02/22/23
- Joining multiple tables, using aggregate functions and ordering by statements are all common SQL concepts. Here are some resources for learning more about each:
- Joining Multiple Tables:
- w3schools: https://www.w3schools.com/sql/sql_join.asp
- SQLBolt: https://sqlbolt.com/lesson/select_queries_with_joins
- Using Aggregate Functions:
- w3schools: https://www.w3schools.com/sql/sql_functions.asp
- SQLBolt: https://sqlbolt.com/lesson/select_queries_with_aggregates
- Ordering by Statements:
- w3schools: https://www.w3schools.com/sql/sql_orderby.asp
- SQLBolt: https://sqlbolt.com/lesson/select_queries_order_and_limit
- Here is a query that displays all of the employees who worked on a computer, ordered by the computer's serial number (ascending) and then by employee's last name (ascending):
SELECT Computers.serial_number, Employees.first_name, Employees.last_name FROM Computers JOIN Workstations ON Computers.serial_number = Workstations.computer_serial_number JOIN Employees ON Workstations.employee_id = Employees.id ORDER BY Computers.serial_number ASC, Employees.last_name ASC;
3. Here is a query that displays the total number of labor hours spent on each computer, ordered by total hours (descending):
SELECT Workstations.computer_serial_number, SUM(Workstations.hours_worked) AS total_hours FROM Workstations GROUP BY Workstations.computer_serial_number ORDER BY total_hours DESC;
Note that these queries may need to be adjusted based on your specific database schema and data.