Quiz No.
3
DBMS
1.
What is the result of the following SQL query if there are no
matching rows in the right table?
sql
SELECT * FROM employees e LEFT JOIN departments d
ON e.dept_id = d.dept_id;
a) Only rows from the employees table
b) Only rows from the departments table
c) All rows from employees with NULLs for unmatched
departments
d) No rows
2.
• In an SQL query using both INNER and OUTER joins, which of
the following is correct?
• a) INNER join results are combined with LEFT join results
b) OUTER join results are combined with INNER join results
c) LEFT join results are combined with RIGHT join results
d) Each join operation is performed independently
3.
Given two tables, A and B, which of the following SQL
queries will return the Cartesian product of the two tables?
a) SELECT * FROM A INNER JOIN B;
b) SELECT * FROM A LEFT JOIN B;
c) SELECT * FROM A RIGHT JOIN B;
d) SELECT * FROM A, B;
4.
Which of the following statements correctly calculates the
total number of rows in a table?
a) SELECT COUNT(*) FROM table;
b) SELECT COUNT(column) FROM table;
c) SELECT COUNT(ALL) FROM table;
d) SELECT COUNT(1) FROM table;
5.
Given a table sales with columns product_id, quantity, and price,
how do you calculate the total revenue?
a) SELECT SUM(quantity + price) FROM sales;
b) SELECT SUM(quantity * price) FROM sales;
c) SELECT COUNT(quantity * price) FROM sales;
d) SELECT AVG(quantity * price) FROM sales;
6.
How can you group the results by a specific column and filter out groups
with an aggregate value greater than a certain number?
a) GROUP BY column HAVING aggregate_function(column) > value
b) HAVING column GROUP BY aggregate_function(column) > value
c) WHERE column GROUP BY aggregate_function(column) > value
d) ORDER BY column HAVING aggregate_function(column) > value
7.
Given a table employees with columns department_id and salary,
how do you find the average salary of each department?
a) SELECT department_id, SUM(salary) FROM employees GROUP BY department_id;
b) SELECT department_id, AVG(salary) FROM employees GROUP BY department_id;
c) SELECT department_id, COUNT(salary) FROM employees GROUP BY department_id;
d) SELECT department_id, MIN(salary) FROM employees GROUP BY department_id;
8.
How do you select departments with an average salary greater than $50000?
a) SELECT department_id FROM employees WHERE AVG(salary) > 50000;
b) SELECT department_id FROM employees GROUP BY
department_id HAVING AVG(salary) > 50000;
c) SELECT department_id FROM employees HAVING AVG(salary) > 50000;
d) SELECT department_id FROM employees GROUP BY
department_id WHERE AVG(salary) > 50000;
9.
What does the following SQL query do?
sql
SELECT department_id, COUNT(*) FROM employees
GROUP BY department_id HAVING COUNT(*) > 5;
a) It selects all departments with more than 5 employees
b) It selects departments with exactly 5 employees
c) It counts the number of employees in each department
d) It groups employees by department_id
10.
Given a table orders with columns order_id, customer_id, and order_date,
which query finds the number of orders placed by each customer in 2023?
a) SELECT customer_id, COUNT(order_id) FROM orders
WHERE order_date LIKE '2023%' GROUP BY customer_id;
b) SELECT customer_id, COUNT(order_id) FROM orders
GROUP BY order_date LIKE '2023%';
c) SELECT customer_id, COUNT(order_id) FROM orders WHERE
order_date = '2023' GROUP BY customer_id;
d) SELECT COUNT(order_id) FROM orders WHERE
order_date LIKE '2023%' GROUP BY customer_id;
Project Proposal Related
• Compose a five-line introduction for your
project proposal.
Time Off
• The End