January 17, 2006 at 3:27 am
Hello
I have a select statement:
Select date, category, count(*) from MyTable
GroupBy date,category
Result:
01/01/2006 |Employee|20
01/01/2006 |Boss |5
01/02/2006 |Employee|22
01/02/2006 |Boss |6
Now imagine i want to add a fixed category named "Target" with a fixed value in my select statement to have the result:
01/01/2006 |Employee|20
01/01/2006 |Boss |5
01/01/2006 |Target |30
01/02/2006 |Employee|22
01/02/2006 |Boss |6
01/02/2006 |Target |30
Is it possible to do that ?
Thanks
January 17, 2006 at 3:53 am
Select date, category, count(*) AS cnt from MyTable
Group By date,category
UNION ALL
Select date, 'Target' AS category, 30 AS Cnt from MyTable
Group By date
That's one solution. I'm sure there are others.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 17, 2006 at 4:10 am
It works fine, thanks a lot
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply