0% found this document useful (0 votes)
14 views

Assignment 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

SELECT product_price
from product
where product_price > (SELECT AVG(product_price) FROM product)

2. SELECT CONCAT(c.cust_fname, ' ', c.cust_fname) as custFullName, o.order_id


FROM customer c
LEFT JOIN orders o on o.cust_id = c.cust_id
WHERE order_id is null

3. SELECT CONCAT(customer.cust_fname,' ', customer.cust_lname) as cust_name,


COUNT(orders.order_id) AS num_orders
FROM customer
JOIN orders
USING(cust_id)
GROUP BY cust_name;

4. SELECT product_name, COUNT(o.order_id) as order_count


FROM product
JOIN product_in_order pio
USING(product_id)
JOIN orders o
USING(order_id)
WHERE o.order_id >= 1
GROUP BY product_name;
5. SELECT product_name, COUNT(o.order_id) as order_count
FROM product
INNER JOIN product_in_order pio
USING(product_id)
INNER JOIN orders o
USING(order_id)
GROUP BY product_name
HAVING COUNT(o.order_id) >= 10;

6. SELECT city.city, COUNT(customer.cust_id) AS customer_count


FROM customer
INNER JOIN location
USING(location_id)
INNER JOIN city
USING(city_id)
GROUP BY city.city
ORDER BY customer_count DESC
LIMIT 5;

7. SELECT country.country, COUNT(supplier.sup_id) AS supplier_count


FROM supplier
INNER JOIN location
USING(location_id)
INNER JOIN city
USING(city_id)
INNER JOIN country
USING(country_id)
GROUP BY country.country
ORDER BY country.country ASC;

8. SELECT city, AVG(product.product_price * product_in_order.qty_ordered) AS


avg_order_amount
FROM city
INNER JOIN location
USING(city_id)
INNER JOIN customer
USING(location_id)
INNER JOIN orders
USING(cust_id)
INNER JOIN product_in_order
USING(order_id)
INNER JOIN product
USING(product_id)
GROUP BY city
ORDER BY avg_order_amount DESC
LIMIT 1;

9. SELECT dep_id, SUM(employee.salary) AS salary_sum


FROM department
INNER JOIN employee
USING(dep_id)
GROUP BY dep_id
ORDER BY salary_sum DESC;
10. SELECT proj_name, budget, COUNT(work_on.emp_id) AS emp_num
FROM project
INNER JOIN work_on
USING(proj_id)
GROUP BY proj_name, budget
ORDER BY budget DESC
LIMIT 1;

You might also like