SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql basic
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

simon471
Starting Member

3 Posts

Posted - 02/12/2013 :  08:54:06  Show Profile  Reply with Quote
how to code this in sql??
Generate a list showing the total income for a particular year"

Edited by - simon471 on 02/12/2013 23:50:45

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 02/12/2013 :  08:55:27  Show Profile  Visit webfred's Homepage  Reply with Quote
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 - 02/12/2013 :  09:04:22  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 02/12/2013 :  09:07:58  Show Profile  Reply with Quote
Post Table Structures and then it is easy to provide exact solution
I think you are practicing on Oracle....
--
Chandu

Edited by - bandi on 02/12/2013 09:09:07
Go to Top of Page

simon471
Starting Member

3 Posts

Posted - 02/12/2013 :  09:12:44  Show Profile  Reply with Quote
the structure...

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 02/13/2013 :  05:27:04  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000