Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Group ,Sum ,Inner join ..How to do it ??
Group ,Sum ,Inner join ..How to do it ??
Rate Topic
Display Mode
Topic Options
Author
Message
nvoyatzopoulos
nvoyatzopoulos
Posted Sunday, November 11, 2012 12:26 AM
Forum Newbie
Group: General Forum Members
Last Login: Sunday, November 11, 2012 10:10 AM
Points: 2,
Visits: 2
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 !
Post #1383426
Jeff Moden
Jeff Moden
Posted Sunday, November 11, 2012 9:02 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
nvoyatzopoulos (11/11/2012)
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 !
I suspect that you don't have an answer yet because there's just not enough information to go on. For example, you say you have 3 tables but show the data for only one and that data isn't readily consumable for someone to help you.
With that thought in mind, please read the article at the first link in my signature line below for how to give your post the absolute best chance to be answered.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1383446
nvoyatzopoulos
nvoyatzopoulos
Posted Sunday, November 11, 2012 10:13 AM
Forum Newbie
Group: General Forum Members
Last Login: Sunday, November 11, 2012 10:10 AM
Points: 2,
Visits: 2
the other 2 tables just have data that we don't use except the companyid. so we just want to join the tables in companyid that is the same in all tables . all the other fields are in the second one ..
thanks
Post #1383454
Jeff Moden
Jeff Moden
Posted Sunday, November 11, 2012 3:17 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
nvoyatzopoulos (11/11/2012)
the other 2 tables just have data that we don't use except the companyid. so we just want to join the tables in companyid that is the same in all tables . all the other fields are in the second one ..
thanks
Then what is the purpose of the joins if you have all the data that you need for this exercise all in one?
Also, if it really is one just one table with the data you're concerned with, it should be even easier for you to post some readily consumable data. Again, please read the article at the first link in my signature line below.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1383472
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.