Need Query.
-
Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks
Binod K. (Miles to go before I sleep)
-
Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks
Binod K. (Miles to go before I sleep)
This is what you need, BUT ... next time, post some code that you tried here so we know that we are not doing all your job :)
SELECT
Date
, [2] AS [Total 2]
, [3] AS [Total 3]
FROM YOUR_TABLE_NAME
PIVOT (
COUNT( Status )
FOR Status IN ( [2] , [3] )
) AS p -
Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks
Binod K. (Miles to go before I sleep)
select distinct [date], (select count(t1.status) from MyTable as t1 where status=2 and t1.date=MyTable.[date]) as [Total 2], (select count(t1.status) from MyTable as t1 where status=3 and t1.date=MyTable.[date]) as [Total 3] from MyTable
I Love T-SQL "Don't torture yourself,let the life to do it for you."