数据按照时间统计
本人小菜现在遇到一个问题。
现有数据库
LocationCode ScanTime
OSI-11-31-N 2013-07-17 04:00:18.000
OSI-11-31-N 2013-07-17 05:21:55.000
OSI-11-31-N 2013-07-17 06:00:18.000
VAD-07-01-B 2013-07-17 07:00:18.000
OSI-11-31-N 2013-07-17 08:00:18.000
VAD-07-01-B 2013-07-17 09:00:18.000
OSI-11-31-N 2013-07-18 10:00:18.000
OSI-11-31-N 2013-07-18 11:00:18.000
VAD-07-01-B 2013-07-18 12:00:18.000
OSI-11-31-N 2013-07-18 13:00:18.000
OSI-11-31-N 2013-07-18 14:00:18.000
现在要按照ScanTime统计每天不同LocationCode的数据条数,需要得到的数据如下:
OSI-11-31-N VAD-07-01-B
2013-07-17 4 2
2013-07-18 4 1
貌似很难,求大牛指点
------解决方案--------------------
create table test(LocationCode nvarchar(15),ScanTime datetime)
insert into test values ('OSI-11-31-N','2013-07-17 04:00:18.000')
insert into test values ('OSI-11-31-N','2013-07-17 05:21:55.000')
insert into test values ('OSI-11-31-N','2013-07-17 06:00:18.000')
insert into test values ('VAD-07-01-B','2013-07-17 07:00:18.000')
insert into test values ('OSI-11-31-N','2013-07-17 08:00:18.000')
insert into test values ('VAD-07-01-B','2013-07-17 09:00:18.000')