Quantcast
Channel: Answers for "sum and count with group by in a single column"
Viewing all articles
Browse latest Browse all 6

Answer by mjharper

$
0
0
The syntax error will be because AdjustedDateCompleted can't be summed as I guess it's a datetime field. To get both day by day and total I would do something like this: select AdjustedDateCompleted, COUNT(*) as BRRCompletedApr13 from dbo.shp_BRRPipelineRemediation where AdjustedDateCompleted >='04/01/2013' and AdjustedDateCompleted <'05/01/2013' GROUP BY AdjustedDateCompleted Order By AdjustedDateCompleted UNION ALL select DATENAME(MONTH, AdjustedDateCompleted), COUNT(*) as BRRCompletedApr13 from dbo.shp_BRRPipelineRemediation where AdjustedDateCompleted >='04/01/2013' and AdjustedDateCompleted <'05/01/2013' GROUP BY DATENAME(MONTH, AdjustedDateCompleted) Order By DATENAME(MONTH, AdjustedDateCompleted) Does that give you what you need?

Viewing all articles
Browse latest Browse all 6

Trending Articles