请教一条sql语句
数据记录如下:
dJoinTime
-----------------------
2007-07-27 11:16:46.683
2007-07-31 14:14:52.280
2007-08-08 13:58:16.670
2007-08-08 14:32:11.327
2007-08-13 14:08:45.373
2007-08-14 15:14:56.607
我现在想问的是;
按日期分组统计记录,统计出同一天的记录数,结果应该如下
dJoinTime total
-----------------------
2007-07-27 11:16:46.683 1
2007-07-31 14:14:52.280 1
2007-08-08 13:58:16.670 2
2007-08-13 14:08:45.373 1
2007-08-14 15:14:56.607 1
------解决方案--------------------Jinglecat(晓风残月 > > 问题需简洁,错误要详细) ( ) 信誉:94 2007-08-16 14:05:53 得分: 0
我上面的有问题, 因为 dJoinTime 没有包含在分组列中
try ->
SELECT MIN(dJoinTime), COUNT(*) AS total FROM tbl GROUP BY DatePart(dd, dJoinTime)
---------------------
GROUP BY DatePart(dd, dJoinTime) ?!
這麼做很危險
先看看這兩個的結果
Select DatePart(dd, '2007-07-01 ')
Select DatePart(dd, '2007-08-01 ')