c#中使用select 语句统计时间段记录条数的问题数据如下id  name   记录时间
1    aa   2010-2-23 12:44:27
2    bb   2010-3-12 15:22:11
3    aa   2010-3-13 13:00:00
4    cc   2011-3-21 12:21:33
5    cc   2011-9-10 12:23:11我想统计出该表中“记录时间”从12:00:00至13:00:00的记录有多少条
怎么使用?
我主要是想统计从2009年至2010年每天24小时,各时段的记录数。
请高人指点下。

解决方案 »

  1.   

    between 时间1 and 时间2 
      

  2.   

    select count(name) as mycount,datepart('h',"记录时间") from table group by datepart('h',"记录时间") where datepart('yy',记录时间}>=2009 and 
    datepart('yy',记录时间}<=2010"
      

  3.   

    select count(name) as mycount,datepart('h',"记录时间") from table group by datepart('h',"记录时间") where datepart('yy',记录时间}>=2009 and  
    datepart('yy',记录时间)<=2010"
      

  4.   


    select id name,记录时间 from 表名 where convert(varchar(5),记录时间 ,108) between '12:00' and '13:00';--输出所有记录
      

  5.   


    select id name,convert(varchar(5),记录时间 ,108) as 记录时间   from 表名 where convert(varchar(5),记录时间 ,108) between '12:00' and '13:00';--输出所有记录
      

  6.   

    大哥,报错呀
    select id name,convert(varchar(5),记录时间 ,108) as 记录时间   from 表名 where convert(varchar(5),记录时间 ,108) between '12:00' and '13:00';给我说说select id name 什么意思?
    convert()具体怎么用?
      

  7.   

    convert是转型,select id name要加一个逗号看看
    select id, name,convert(varchar(5),记录时间 ,108) as 记录时间 from 表名 where convert(varchar(5),记录时间 ,108) between '12:00' and '13:00';应该不会错了吧?