Comp1168 Lab 7-1
Comp1168 Lab 7-1
Name: Yash
Anuj Zinzuvadiya
Moond
CRN: 50146
Student ID: 101475983
101544121
Date: 03-16-2025
Query:
SELECT
COUNT(*) AS No_of_Payments,
SUM(payment_total) AS Total_amount_paid,
AVG(payment_total) AS Average_Amount,
MIN(payment_total) AS Minmum_payment,
MAX(payment_total) AS Maximum_payment
FROM ap.invoices
WHERE payment_total > 0;
Query:
SELECT
vendor_state,
vendor_city,
vendor_zip_code,
COUNT(DISTINCT v.vendor_id) AS Total_vendors,
SUM(i.payment_total) AS Total_payments
FROM ap.vendors v
JOIN ap.invoices i ON v.vendor_id = i.vendor_id
GROUP BY vendor_state,vendor_city,vendor_zip_code ORDER BY
vendor_state ASC;
Question 3: Create a query that returns the Customers’ full names, and
total number of items ordered by them for each order date and the total
invoiced amount for all orders date-wise for those days only when the
company processed more than 1 order.[use om]
Query:
SELECT
CONCAT(c.customer_last_name, ',',c.customer_first_name) AS
Customer_name, o.order_date,
COUNT(od.order_qty) AS Total_items_ordered,
SUM(i.unit_price) AS Total_invoiced_amount
FROM om.customers c
JOIN om.orders o ON c.customer_id = o.customer_id
JOIN om.order_details od ON o.order_id = od.order_id
JOIN om.items i ON od.item_id = i.item_id
GROUP BY c.customer_first_name, c.customer_last_name,o.order_date
HAVING COUNT(od.order_qty)>1
ORDER BY Customer_name ASC;
Question 4a: We can also find out the Grand Total for the
aggregated column by using the ROLL UP operator
Query:
SELECT
IFNULL(d.department_name, 'TOTAL=') AS Department_name,
COUNT(e.employee_id) AS Total_employees
FROM ex.departments d
JOIN ex.employees e ON d.department_number = e.department_number
GROUP BY d.department_name WITH ROLLUP
ORDER BY Total_employees;