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 |
simon471
Starting Member
3 Posts |
Posted - 2013-02-12 : 08:54:06
|
how to code this in sql??Generate a list showing the total income for a particular year" |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-02-12 : 08:55:27
|
We are not doing homework - is it homework?What have you done so far and where is your problem? Too old to Rock'n'Roll too young to die. |
|
|
simon471
Starting Member
3 Posts |
Posted - 2013-02-12 : 09:04:22
|
im learning on my own..that cant be a homework..1) [not sure if this is correct] CREATE VIEW CustomerIncome AS SELECT SUM( UnitPrice * Quantity ) AS TotalIncome FROM customers JOIN sales USING ( CustomerID ) GROUP BY CustomerID;FROM CustomerIncomeWHERE Year in(SELECT Year FROM TimeTble where Year = *); |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-12 : 09:07:58
|
Post Table Structures and then it is easy to provide exact solutionI think you are practicing on Oracle.... --Chandu |
|
|
simon471
Starting Member
3 Posts |
Posted - 2013-02-12 : 09:12:44
|
the structure... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-13 : 05:27:04
|
it should be if you're using sql serverSELECT c.CompanyName,SUM( UnitPrice * Quantity ) AS TotalIncome FROM customers cJOIN sales sON s.CustomerID = c.CustomerIDINNER JOIN Time tON t.TimeID = s.TimeID WHERE t.Year= '2012'--put your year value hereGROUP BY c.CompanyName ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|