I have what is probably a simple problem and I guess I'm just looking
for whatever solutions you all can suggest...
I have this query:
Select columnA , sum(columnB) as VAL from myTable where
columnA in ('01,'02') group by columnA
which may return:
columnA VAL
-- --
01 100.00
02 200.00
Just using SQL, I'd like to return a table that looks like:
columnA VAL
-- --
01 300.00
and I don't want to use the query:
Select '01', sum(columnB) as VAL from myTable where
columnA in ('01','02')
Any suggestions? Your help is much appreciated.
Marcbrownjenkn@.aol.com wrote:
> I have what is probably a simple problem and I guess I'm just looking
> for whatever solutions you all can suggest...
> I have this query:
> Select columnA , sum(columnB) as VAL from myTable where
> columnA in ('01,'02') group by columnA
> which may return:
> columnA VAL
> -- --
> 01 100.00
> 02 200.00
> Just using SQL, I'd like to return a table that looks like:
> columnA VAL
> -- --
> 01 300.00
>
> and I don't want to use the query:
> Select '01', sum(columnB) as VAL from myTable where
> columnA in ('01','02')
> Any suggestions? Your help is much appreciated.
> Marc
Maybe like this:
SELECT MIN(columnA) AS columnA, SUM(columnB) AS val
FROM myTable
WHERE columnA IN ('01','02');
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment