如何使用T-SQL查找在给定日期创建的记录总数?

Tes*_*act 1 t-sql database grouping

我需要找出在给定日期创建的记录总数.

例如

ID CreatedDate
1 17/07/2009
2 12/07/2009
3 17/07/2009
4 05/07/2009
5 12/07/2009
6 17/07/2009

输出:

3记录创建于17/07/2009
2记录创建于12/07/2009
1记录创建于05/07/2009

编辑

在测试Chris Roberts在SQL中包含格式的第二个建议后,我得到了这个错误:

Syntax error converting the varchar value ' Records were created on ' to a column of data type int.
Run Code Online (Sandbox Code Playgroud)

有谁知道如何重做解决方案,使其有效?

Chr*_*rts 6

您应该能够使用以下SQL获取您所拥有的数据...

SELECT COUNT(ID), CreatedDate FROM MyTable GROUP BY CreatedDate

或者 - 如果你想在SQL中进行格式化,那么......

SELECT CONVERT(varchar, COUNT(ID)) + ' Records were created on ' + CONVERT(varchar, CreatedDate) FROM MyTable GROUP BY CreatedDate

祝好运!