各位大虾:      我有一个一组数据,表结构为:姓名,日期,名称 数据为:
  a  2011-12-1 甲
  a  2011-12-1 乙
  a  2011-12-2 丙
  a  2011-12-3 丙
  b  2011-12-3 甲我想统计日期 从2011-12-1 到 2011-12-3的一个人数统计,
如果同姓名同个日期人数统计为1,同姓名不同日期人数统计为累加如上面数据 a的人数统计就为 3 b的人数就为1

解决方案 »

  1.   

    with t as ( select 'a' as name,'2011-12-1' as d,'甲' as mingcheng from dual 
    union  select 'a','2011-12-1' ,'乙' from dual 
    union select 'a','2011-12-2' ,'丙' from dual 
    union select 'a','2011-12-3' ,'丙' from dual 
    union select 'b','2011-12-3' ,'甲' from dual )
    select name,count(*) from (select name,d from t group by name,d ) group by name
     
      

  2.   

    select name,count(*) from (select name,d from t group by name,d ) group by name
      

  3.   


    select t.name01
           ,count(distinct t.date01) as Num
    from( select name01, date01 from temp1 
          where date01 between to_date('2011-12-01','yyyy-mm-dd') 
          and to_date('2011-12-03','yyyy-mm-dd')+1 
    ) t
    group by t.name01
    结果如下:
    select t.name01
           ,count(distinct t.date01) as Num
    from( select name01, date01 from temp1 
          where date01 between to_date('2011-12-01','yyyy-mm-dd') 
          and to_date('2011-12-03','yyyy-mm-dd')+1 
    ) t
    group by t.name01
      

  4.   

    --结果如下:
    NAME01  NUM 
    a 3
    b 1
      

  5.   

    a 2011-12-1 甲
      a 2011-12-1 乙
      a 2011-12-2 丙
      a 2011-12-3 丙
      b 2011-12-3 甲加个distinct子查询去重就可以了。
    SELECT COUNT(*) FROM (SELECT DISTINCT id,TRUNC(dt),name FROM TABLE);
      

  6.   


     create table user_info(
            user_id varchar2(10),
            date_time varchar2(10),
            user_name varchar2(50)
     );
     统计sql:
    select t1.user_id,count(*) from 
    (
       select 
           t.user_id,t.date_time,count(*) 
       from user_info t
       where to_date(date_time,'yyyy-MM-dd')>=to_date('2011-12-1','yyyy-MM-dd') 
       and to_date(date_time,'yyyy-MM-dd')<=to_date('2011-12-3','yyyy-MM-dd')
       group by t.user_id,t.date_time
    ) t1 
    group by t1.user_id
    order by t1.user_id
      

  7.   


    select t1.user_id,count(*) from 
    (
       select 
           t.user_id,t.date_time,count(*) 
       from user_info t
       where to_date(date_time,'yyyy-MM-dd')>=to_date('2011-12-1','yyyy-MM-dd') 
       and to_date(date_time,'yyyy-MM-dd')<=to_date('2011-12-3','yyyy-MM-dd')
       group by t.user_id,t.date_time
       having count(*)<=1
    ) t1 
    group by t1.user_id
    order by t1.user_id
      

  8.   


    select 姓名,count(distinct 日期) as num
    from tab_name
    where 日期>=to_date('2011-12-01','yyyy-mm-dd') and 日期<=to_date('2011-12-03','yyyy-mm-dd') 
    group by 姓名
      

  9.   

    这个简单的想法我试过了,是错误的,逻辑是对的,语句是错误的,日期没在group by 函数后面!
      

  10.   

    最简单的,就用
     count(distinct 名称) 可以了 select 姓名, count(distinct )
             from table
         where 日期 bewteen 2011-12-1 and 2011-12-3 ( 日期格式自已调整一下)
      

  11.   

    上面忘加 group by 了 select 姓名, count(distinct )
             from table
         where 日期 bewteen 2011-12-1 and 2011-12-3 ( 日期格式自已调整一下)
      group by 姓名
      

  12.   

    select count(distinct 名称),姓名 from tb where to_char(日期,'yyyy-mm-dd') between 2011-12-01 and 2011-12-03 group by 姓名
      

  13.   

    select count(*)
    from (
    select
          distinct 姓名
           ,日期
      from 表
    )