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
 sql basic

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.
Go to Top of Page

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 CustomerIncome
WHERE Year in(SELECT Year FROM TimeTble where Year = *);
Go to Top of Page

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 solution
I think you are practicing on Oracle....
--
Chandu
Go to Top of Page

simon471
Starting Member

3 Posts

Posted - 2013-02-12 : 09:12:44
the structure...

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-13 : 05:27:04
it should be if you're using sql server

SELECT c.CompanyName,SUM( UnitPrice * Quantity ) AS TotalIncome
FROM customers c
JOIN sales s
ON s.CustomerID = c.CustomerID
INNER JOIN Time t
ON t.TimeID = s.TimeID
WHERE t.Year= '2012'--put your year value here
GROUP BY c.CompanyName



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -