Hi i have a table as below
year month income source
___________________________
2008 06 100 source1
2008 06 80 source2
2008 06 200 source1
2008 06 100 source2
my output is
year month income
___________________
2008 06 120 (sum(rev) source1 - sum(rev) source2)
may i know what is the SQL query statement can do that????
1 1082 ck9663 2,878
Recognized Expert Specialist
Try this: - declare @IncomeTable table (yr int, mon varchar(2), income money, src varchar(10))
-
-
insert into @IncomeTable values(2008, '06', 100.00, 'source1')
-
insert into @IncomeTable values(2008, '06', 80.00, 'source2')
-
insert into @IncomeTable values(2008, '06', 200.00, 'source1')
-
insert into @IncomeTable values(2008, '06', 100.00, 'source2')
-
-
select source1.yr, source1.mon, source1.source_income - source2.source_income
-
from
-
(select yr, mon, src, SUM(income) as source_income
-
from @IncomeTable
-
where src = 'source1'
-
group by yr, mon, src) source1
-
inner join
-
(select yr, mon, src, SUM(income) as source_income
-
from @IncomeTable
-
where src = 'source2'
-
group by yr, mon, src) source2 on
-
source1.yr = source2.yr and source1.mon = source2.mon
-- CK
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rob |
last post by:
I have a form - when you click the submit button, it appends a
variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable)
It also opens a new page. Now, that some_dynamic_variable is...
|
by: Stefan Bauer |
last post by:
Hi NG,
we've got a very urgent problem... :(
We are importing data with the LOAD utility. The input DATE field data
is in the format DDMMYYYY (for days) and MMYYYY (for months).
The target...
|
by: Tamir Khason |
last post by:
Follwing the struct:
public struct TpSomeMsgRep
{
public uint SomeId;
|
by: zeyais |
last post by:
Here is my HTML:
<style>
..leftcolumn{float:left;width:300px;border: 1px solid #ccc}
..rtcolumn{float:left;width:600px;border: 1px solid #ccc}
</style>
<body>
<div class="leftcolumn"...
|
by: dembla |
last post by:
Hey Frnds can anyone help me in this
i need a program in 'c'
PROGRAM to print NxN Matrix
9 1 8 1 2 3
2 7 3 as 4 5 6
6 4 5 7 8 9
in sorted form
| |
by: alok sengar |
last post by:
hi,
I have already tried this URL's code
"http://www.java2s.com/Code/CSharp/Network/SimpleSNMP.htm"
but I am getting error when i am creating a UDP type Socket and recieving
packet from this...
|
by: Saps |
last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need
a way to call these from my asp page so the user can run them from the
browser. Meaning i have a page with a list of all...
|
by: N. Spiker |
last post by:
I am attempting to receive a single TCP packet with some text ending with
carriage return and line feed characters. When the text is send and the
packet has the urgent flag set, the text read from...
|
by: rajesh.us.it.recruiter |
last post by:
Hi Guys/Partners,
We have a URGENT Requirement for Perl Programmer with H1 visa in
India/US for one of our prestigious Client. Location : New Jersey
Requirements :
Should be very strong in...
|
by: Cirene |
last post by:
I used to use the Web Deployment Project with my VS2005 projects.
Now I've fully upgraded to VS2008. Do I have to download a new version of
the Web Deployment Project? If so where can I find...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |