
FIT 9132 Week 9
Authored by Arnab Biswas
Computers
University
Used 5+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
8 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Which of the following SQL queries would retrieve the total sales amount for each month in the year 2022 from the "sales" table?
SELECT MONTH(TO_DATE(sale_date)) AS month, SUM(sale_amount) AS total_sales FROM sales WHERE YEAR(TO_DATE(sale_date)) = 2022 GROUP BY MONTH(TO_DATE(sale_date))
SELECT MONTH(sale_date), SUM(sale_amount) FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY MONTH(sale_date)
SELECT EXTRACT(MONTH FROM sale_date), SUM(sale_amount) FROM sales WHERE EXTRACT(YEAR FROM sale_date) = 2022 GROUP BY EXTRACT(MONTH FROM sale_date)
SELECT MONTH(sale_date), SUM(sale_amount) FROM sales WHERE YEAR(sale_date) = 2022 GROUP BY sale_date
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Suppose you have two tables: "employees" and "departments". The "employees" table has the columns emp_id, emp_name, salary, dept_name, dep_id. The "departments" table has the columns dept_id and dept_name. Write a SQL query to find the average salary for each department, along with the department name.
SELECT departments.dept_name, AVG(employees.salary) AS avg_salary FROM employees JOIN departments ON employees.dep_id = departments.dept_id GROUP BY departments.dept_name;
SELECT dept_name, AVG(salary) AS avg_salary FROM employees, departments WHERE employees.dep_id = departments.dept_id GROUP BY departments.dept_name;
SELECT dept_name, AVG(salary) AS avg_salary FROM employees NATURAL JOIN departments GROUP BY dept_name;
SELECT dept_name, AVG(salary) AS avg_salary FROM departments LEFT JOIN employees ON departments.dept_id = employees.dept_id GROUP BY dept_name;
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Suppose you have a table called "orders" with the columns order_id, customer_id, order_date, and order_total. Write a SQL query to find the top 10 customers with the highest total order amount.
SELECT customer_id,
SUM(order_total) AS total_spent
FROM orders
GROUP BY
customer_id
HAVING
total_spent > 0
ORDER BY
total_spent
LIMIT 10;
SELECT
customer_id,
SUM(order_total) AS total_spent
FROM orders
WHERE
order_total > 0
GROUP BY
customer_id
ORDER BY
total_spent
LIMIT 10;
SELECT
customer_id,
SUM(order_total) AS total_spent
FROM orders
GROUP BY
customer_id
ORDER BY
2 DESC
LIMIT 10;
SELECT
customer_id,
SUM(order_total) AS total_spent
FROM orders
GROUP BY
customer_id
ORDER BY
total_spent DESC
LIMIT 10;
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Suppose you have a table called "products" with the columns product_id, product_name, price, and category. Write a SQL query to find the product with the highest price in each category.
SELECT product_name, MAX(price) FROM products GROUP BY category ORDER BY MAX(price) DESC LIMIT 1;
SELECT product_name, price FROM products WHERE price = ( SELECT MAX(price) FROM products WHERE category = p.category ) GROUP BY category;
SELECT p1.product_name, p1.price FROM products p1 JOIN ( SELECT category, MAX(price) AS max_price FROM products GROUP BY category ) p2 ON p1.category = p2.category AND p1.price = p2.max_price ORDER BY p1.category ASC;
SELECT product_name, MAX(price) FROM products GROUP BY category HAVING MAX(price) = ( SELECT MAX(price) FROM products );
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Suppose you have two tables: "orders" and "order_details". The "orders" table has the columns order_id, customer_id, order_date, and order_total. The "order_details" table has the columns order_id, product_id, quantity, and price. Write a SQL query to find the total revenue generated by each customer.
SELECT o.customer_id, SUM(od.quantity) * SUM(od.price) AS revenue FROM orders o JOIN order_details od ON o.order_id = od.order_id GROUP BY o.customer_id
SELECT o.customer_id, SUM(od.quantity * od.price) AS revenue FROM orders o JOIN order_details od ON o.order_id = od.order_id GROUP BY o.customer_id
SELECT o.customer_id, SUM(od.quantity) + SUM(od.price) AS revenue FROM orders o JOIN order_details od ON o.order_id = od.order_id GROUP BY o.customer_id
SELECT o.customer_id, SUM(od.quantity) * AVG(od.price) AS revenue FROM orders o JOIN order_details od ON o.order_id = od.order_id GROUP BY o.customer_id
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider a table called "students" with the following columns: student_id, student_name, major, and gpa. Write a SQL query to find the student(s) with the highest GPA for each major.
SELECT major, student_id, student_name, gpa FROM students s1 WHERE gpa = ( SELECT MAX(gpa) FROM students s2 WHERE s1.major = s2.major )
SELECT major, MAX(gpa) AS max_gpa FROM students GROUP BY major
SELECT major, student_id, student_name, gpa FROM students WHERE gpa = MAX(gpa) GROUP BY major
SELECT major, student_id, student_name, gpa FROM students s1 WHERE NOT EXISTS ( SELECT 1 FROM students s2 WHERE s1.major = s2.major AND s2.gpa > s1.gpa )
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Suppose you have a table called "invoices" with the following columns: invoice_id, customer_id, invoice_date, and invoice_amount. Write a SQL query to find all invoices that have a duplicate invoice amount, and display them in descending order of invoice amount.
SELECT invoice_amount, COUNT(*) as count FROM invoices GROUP BY invoice_amount HAVING COUNT(*) > 1 ORDER BY invoice_amount DESC;
SELECT invoice_id, customer_id, invoice_date, invoice_amount FROM invoices WHERE invoice_amount IN (SELECT invoice_amount FROM invoices DISTINCT invoice_amount HAVING COUNT(*) > 1) ORDER BY invoice_amount DESC;
SELECT i1.invoice_id, i1.customer_id, i1.invoice_date, i1.invoice_amount FROM invoices i1 JOIN (SELECT invoice_amount FROM invoices GROUP BY invoice_amount HAVING COUNT(*) > 1) i2 ON i1.invoice_amount = i2.invoice_amount ORDER BY i1.invoice_amount DESC;
SELECT invoice_id, customer_id, invoice_date, invoice_amount FROM invoices WHERE invoice_amount IN (SELECT invoice_amount FROM invoices WHERE invoice_amount IS NOT NULL GROUP BY invoice_amount) ORDER BY invoice_amount DESC;
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
System Bus
Quiz
•
University - Professi...
10 questions
Stack & Queue
Quiz
•
University
10 questions
Google Workspace
Quiz
•
University
10 questions
Quiz - CSE
Quiz
•
University
11 questions
Technology Morning Tea Quiz
Quiz
•
KG - Professional Dev...
10 questions
Java Script. Parte 1.
Quiz
•
University
10 questions
104-P-01: Delegates and lambdas
Quiz
•
University
10 questions
Visual Basic 2010
Quiz
•
8th Grade - University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
29 questions
Alg. 1 Section 5.1 Coordinate Plane
Quiz
•
9th Grade
22 questions
fractions
Quiz
•
3rd Grade
11 questions
FOREST Effective communication
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
7 questions
Fragments, Run-ons, and Complete Sentences
Interactive video
•
4th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
10 questions
DNA Structure and Replication: Crash Course Biology
Interactive video
•
11th Grade - University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
5 questions
Examining Theme
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University