Re: Can SQL do this?
- From: "lowieann" <lowieann@xxxxxxxxxxx>
- Date: Tue, 29 May 2007 17:37:14 -0400
Thanks Bob.
I'll try it in the AM.
Bruce
"Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx> wrote in message
news:OXN4wIfoHHA.3968@xxxxxxxxxxxxxxxxxxxxxxx
lowieann wrote:
I am using Microsoft ADO 2.8 with VB6 and would to know if SQL can do
this.
By "SQL", do you mean SQL Server? if so, which version?
One table that looks like this.
ID Code Value
01 01 1.00
01 01 2.00
01 99 1.50
01 99 1.25
02 02 1.00
03 34 3.50
03 99 1.25
I would like to sum the values and have the returned record set to
look like this:
ID Code Sum Other Sum
You cannot have two columns with the same name ...
01 01 3.00 99 2.75
02 02 1.00
03 34 3.50 99 1.25
The point is to have the sum of Code 99 be part of the returned
recordset of ID's, in this case ID=01 and 03.
Assuming SQL Server 7 and above, try this (untested, but it should give
you the direction you need):
select q1.ID, q1.Code, q1.[Sum],q2.Other,OtherSum FROM
(select ID, Code, Sum(Value) As [Sum]
From Table
where Code <> '99'
group by ID, Code) q1
LEFT JOIN
(select ID, Code As Other, Sum(Value) As OtherSum
From Table
where Code = '99'
group by ID, Code) q2
ON q1.Code = q2.Code
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- Follow-Ups:
- Re: Can SQL do this?
- From: lowieann
- Re: Can SQL do this?
- References:
- Can SQL do this?
- From: lowieann
- Re: Can SQL do this?
- From: Bob Barrows [MVP]
- Can SQL do this?
- Prev by Date: Re: FMTONLY problems
- Next by Date: Re: FMTONLY problems
- Previous by thread: Re: Can SQL do this?
- Next by thread: Re: Can SQL do this?
- Index(es):
Relevant Pages
|
|