Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 An easy question yet hard for me

Author  Topic 

Manticure
Starting Member

5 Posts

Posted - 2008-09-26 : 01:27:58
Basically I am kinda lost right now. I can do basica queries but I got stuck on this question:
Consider the following tables:

Customer (CustNo, CustFirstName, CustLastName, CustStreet, CustCity, CustState, CustZip, CustBal)

Employee (EmpNo, EmpFirstName, EmpLastName, EmpPhone, EmpEmail, SupEmpNo, EmpCommRate)

Product (ProdNo, ProdName, ProdMfg, ProdQOH, ProdPrice, ProdNextShipDate)

OrderTbl (OrdNo, OrdDate, CustNo, EmpNo, ShpName, ShpStreet, ShpCity, ShpState, ShpZip)

OrdProd (OrdNo, ProdNo, Qty)

List the average balance and number of customers by city. Only include customers residing in Washington state ('WA'). Eliminate cities in the result with less than two customers in the city.

I dont have much of a clue how to do that, all I came up with is this for a start:

SELECT CustBal
FROM Customer
AVG(CustBal)
INNER JOIN OrdProd
ON Product.ProdNo = OrdProd.ProdNo
INNER JOIN OrderTbl
ON OrdProd.OrdNo = OrderTbl.OrdNo
INNER JOIN Customer
ON OrderTbl.CustNo = Customer.CustNo
WHERE CustState = 'WA
AND COUNT(CustCity) > 1;

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-26 : 01:33:14
[code]SELECT CustCity,COUNT(CustNo) AS CustCount,AVG(CustBal) AS AvgCustBal
FROM Customer
WHERE CustState='WA'
GROUP BY CustCity
HAVING COUNT(CustNo)>=2[/code]
Go to Top of Page
   

- Advertisement -