Thread: MS SQL Server General Questions/Group query by hours and by days

Group query by hours and by days

Here it is by hours first:



select



Convert(varchar(2), [EndDate],114) as hh,count(*) from [dbo].[Vote] group by Convert(varchar(2), [EndDate],114)

 


order by Convert(varchar(2), [EndDate],114)

 


And now by days:



select


 


Convert(varchar(8), [EndDate],112) as dd,count(*) from [dbo].[Vote] group by Convert(varchar(8), [EndDate],112)

 


order by Convert(varchar(8), [EndDate],112)