write a query to display each zip code and the total owed by customers in that z
ID: 3692676 • Letter: W
Question
write a query to display each zip code and the total owed by customers in that zip code. Only include zip codes for the total owed is above 1000
SalesRep Customer PK ReplD int PK CustomerlD int LastName FirstName CommissionRatedecimal(10,2) varchar(20) varchar(20) LastName varchar(20) FirstName varchar(20) Street City State Zipcode Balance varchar(20) varchar(20) char(2) Order char(5) decimal(10,2) int PK OrderID int FK1ReplD FK1 CustomerlD int OrderDate date ShipDate date Part PK PartID int OrderLine Description varchar(20) UnitsOnHandint ItemClass Retail Cost PK,FK1OrderlD int PK,FK2 PartlDint char(4) decimal(10,2) decimal(10,2) Quantity intExplanation / Answer
Answer:
select Zipcode, sum(Balance) group by Zipcode having sum(Balance) > 1000 from Customer
Explanation:
sum function is used to calculate the sum of the given column in the brackets.
The following query results in the total of the balances of all the customers.
select sum(Balance) from customer
But we want to display each zip code so we have to use group by clause.
Also we want to display the zip codes having total balances greater than 1000
So we must use having clause why because where clause can not be used with agregate functions.
so the answer is
select Zipcode, sum(Balance) group by Zipcode having sum(Balance) > 1000 from Customer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.