Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.) Write a single, simple SELECT statement from the employees table that return

ID: 3919473 • Letter: 1

Question


1.)              Write a single, simple SELECT statement from the employees table that returns:

·       the minimum department_number aliased as min_dno

·       and the maximum department_number aliased as max_dno

2.)              Write a single, simple SELECT statement from the invoices table that returns:

·       the average invoice_total aliased as avg_invoice_total

·       and the average payment_total aliased as avg_payment_total

·       and the average credit_total aliased as avg_credit_total

3.)              Write a single, simple SELECT statement from the items table that returns:

·       the count of the unique unit_price values aliased as count_distinct_unit_price

4.)              Write a single, simple SELECT statement from the order_details table that returns:

·       the sum of order_qty aliased as sum_order_qty

Explanation / Answer

1)

SELECT MIN(department_number) AS min_dno , MAX(department_number) AS max_dno

FROM employees;

In above query min function is used to find minimum of all department numbers.

AS is used for aliasing

2)

SELECT AVG(invoice_total) AS avg_invoice_total, AVG(payment_total) AS avg_payment_total, AVG(credit_total) AS avg_credit_total

FROM invoices;

In above, query AS is used for aliasing and AVG() is used to find the average.

3)

SELECT COUNT(DISTINCT unit_price) AS count_distinct_unit_price

FROM items;

In above query, distinct is used to find the unique unit_price and count is used to count the number of unique unit_price.

4)

SELECT SUM(order_qty) AS sum_order_qty

FROM order_details ;

In above query, SUM() is used to find the sum of order_qty