表A 如下
名字  创建时间
A     2007-3-13 17:58:17
B     2007-3-13 17:00:17
A     2007-3-14 17:58:17
A     2007-3-15 17:58:17那么怎么实现 在某个时间断这样显示 
比如 在 2007-3-13 17:58:00  到 2007-3-14 18:58:17
A    2
B    1而在 在 2007-3-13 17:58:00  到 2007-3-16 18:58:17
A    3
B    1

解决方案 »

  1.   

    select
        名字,count(*) 
    from 
        表A 
    where
        创建时间 between 时间1 and 时间2
    group by
        名字
      

  2.   

    select 名字,sum(1) from A where 创建时间 between 时间1 to 时间2 group by 名字;
      

  3.   

    Select 
    名字,
    Count(*) As [次數]
    From
    A
    Where 创建时间 Between '2007-3-13 17:58:00' And '2007-3-14 18:58:17'
    Group By 名字
    Select 
    名字,
    Count(*) As [次數]
    From
    A
    Where 创建时间 Between '2007-3-13 17:58:00' And '2007-3-16 18:58:17'
    Group By 名字
      

  4.   

    select 名字,sum(1) from A where 创建时间 between 时间1 and 时间2 group by 名字;
      

  5.   

    select  名字,count(*) from 表A where  创建时间 between 时间1 and 时间2 group by 名字
    order by 名字
      

  6.   

    create table t
    (
      名字 varchar(1),
      创建时间 datetime
    )insert t 
    select 'A',cast('2007-3-13 17:58:17' as datetime) union all
    select 'B',cast('2007-3-13 17:00:17' as datetime) union all
    select 'A',cast('2007-3-14 17:58:17' as datetime) union all
    select 'A',cast('2007-3-15 17:58:17' as datetime)
    select 名字,num=count(*)
    from t 
    where 创建时间 between  '2007-3-13 17:58:00' and '2007-3-14 18:58:17' 
    group by 名字--result:
    名字    num
    -----------
    A 2
      

  7.   

    假若 表A 还有字段 姓名 那么
    我要将 姓名也选出来 是不是也要group  by 姓名?如果是这样 假设 我这个表还要连接别的表进行查询 并将她们的字段也添加近来
    是不是 也要一一的 group?
      

  8.   

    TO: kourr2004(★★★★★鬼谷子:)★★★★★) 
    呵呵
    这只是我随便写的
    大家明白是这个意思就行了