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

PLEASE WRITE AN ANSWER IN MYSQL WORKBENCH Use a subquery to calculate the averag

ID: 3727300 • Letter: P

Question

PLEASE WRITE AN ANSWER IN MYSQL WORKBENCH

Use a subquery to calculate the average tax amount from each order if the tax amount is not zero, then list the order_ids, customer_id, and tax_amount of the orders with tax amounts higher than the average.

orders table:

Columns:

order_id int(11) AI PK customer_id int(11) order_date datetime ship_amount decimal(10,2) tax_amount decimal(10,2) ship_date datetime ship_address_id int(11) card_type varchar(50) card_number char(16) card_expires char(7) billing_address_id int(11)

Explanation / Answer

NOTE: Asuming That table name is: Costumer_Order . You can change it.

Query :-  

SELECT co.order_id, co.customer_id, co.tax_amount

FROM Costumer_Order co

WHERE co.tax_amount != 0

AND

co.tax_amount >
(SELECT avg(co1.tax_amount) as avgTax FROM Costumer_Order co1) ;

NOTE: You can change Bold words of query with your tabe name.

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote