|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
a little SQL problemfor 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 brownje***@aol.com wrote:
Show quote > I have what is probably a simple problem and I guess I'm just looking Maybe like this:> 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 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 -- |
|||||||||||||||||||||||