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.
| Author |
Topic |
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-30 : 11:43:58
|
| Hi I am trying to figure out how to create this sql statement. "Which employee had the highest percentage increase in sales from 2001 to 2002?"Employee tableEmployeeIDTaxpayerIDLastNameFirstNameHomePhoneBicycle TableEmployeeIDSerialNumberCustomerIDShipDateShipEmployeeSalePriceSalesTaxThis is what I started to do.Select *From Bicycle bJoin Employee con b.EmployeeID = c.EmployeeIDThe shipdate is the when the bicycle is sold. Thanks for any help you can give. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-30 : 12:54:12
|
| [code]SELECT TOP 1 e.*FROM Employee eJOIN (SELECT EmployeeID, (SUM(CASE WHEN YEAR(ShipDate)=2002 THEN SalePrice ELSE 0 END)-SUM(CASE WHEN YEAR(ShipDate)=2001 THEN SalePrice ELSE 0 END))*100.0/SUM(CASE WHEN YEAR(ShipDate)=2001 THEN SalePrice ELSE 0 END) AS [%Inc]FROM BicycleWHERE YEAR(ShipDate) IN (2001,2002)GROUP BY EmployeeID)bON e.EmployeeID=b.EmployeeIDORDER BY b.[%Inc] DESC[/code] |
 |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-30 : 15:57:03
|
| thanks, what is the wildcard Inc doing? |
 |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-30 : 15:58:25
|
| thanks, what is the wildcard Inc doing? |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-11-30 : 16:02:04
|
quote: Originally posted by intern2424 thanks, what is the wildcard Inc doing?
[%Inc] is just an alias that visakh has used to represent percentage increase..u can name it whatever u want. |
 |
|
|
|
|
|