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
 Groups ,Sum and Totals how to do it ??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nvoyatzopoulos
Starting Member

Greece
7 Posts

Posted - 11/11/2012 :  02:23:28  Show Profile  Reply with Quote
Hello , i'm new and i want your help guys! I've 3 tables with one common field (id) .
the data look like this ..
companyid |datetrn |income| expenses | tax income | tax expenses |..
01 |2012/01/01|100 | 0 | 0 | 10 |..
02 |2012/02/15|0 | 150 | 12 | 0 |..
03 |2012/03/20|1500 | 1000 | 0 | 100 |..

so here start the troubles .. I want to join those 3 tables with id (ok with this) and present results like the following ..

inc. sum|exp.sum|tot.period|in.tax sum|ex.tax sum|tot.period
january | 100 | 0 | 100 | 0 | 10 | 10
february | 0 | 150 | 50 | 12 | 0 | -2
march | 1000 | 0 | 1050 | 0 | 100 | 98
........

Is this possible ?

thanks in advance !

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/11/2012 :  07:10:03  Show Profile  Reply with Quote
Based on your description it doesn't look like you will need to join three tables. Also, although the columns in the first table appear to be self-explanatory, it is not clear to me what the columns in the result set are, or how the data in the first table are used to compute the results. So this may be completely wrong, but the general idea would be this:
select
	datename(month,datetrn),
	sum(income) as [inc.sum],
	sum(income+[tax income]) as [tot.period]
from
	YourTable
group by 
	datename(month,datetrn)
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.03 seconds. Powered By: Snitz Forums 2000