表数据如下:
A列      B列      C列         D列 
1         3        1      2012-01-02
2         2        3      2012-01-03
3         1        4      2012-01-04
4         1        3      2012-01-05
2         3        2      2012-01-07
3         4        2      2012-01-08
4         3        1      2012-01-09
count(*)   我想根据A  B  C  三列分组   然后想根据D列某段时间内多少个怎么查询?  D列不在分组条件内

解决方案 »

  1.   

    select count(a),count(b),count(c) from 表名   where  d列>to_date('2012-01-20','yyyy-mm-dd')  and d列>to_date('2012-02-20','yyyy-mm-dd') group by a,b,c 不知道这个是否可以满足需求?
      

  2.   


    --测试表创建
    create table test2(
    a number,
    b number,
    c number,
    d varchar2(20)
    )
    --插入测试数据
    insert into test2(
    select 1,3,1,'2012-01-02' from dual union all
    select 2,2,3,'2012-01-03' from dual union all
    select 3,1,4,'2012-01-04' from dual union all
    select 4,1,3,'2012-01-05' from dual union all
    select 2,3,2,'2012-01-07' from dual union all
    select 3,4,2,'2012-01-08' from dual union all
    select 4,3,1,'2012-01-09' from dual)
    --查询
    select a,b,c,count(1)
    from test2
    where d between '2012-01-04' and '2012-02-05'
    group by a,b,c
    --查询结果
    A       B       C       count
    4 1 3 1
    2 3 2 1
    4 3 1 1
    3 1 4 1
    3 4 2 1
      

  3.   


    --测试表的创建
    create table test2(
    a number,
    b number,
    c number,
    d varchar2(20)
    )
    --插入测试数据
    insert into test2(
    select 1,3,1,'2012-01-02' from dual union all
    select 2,2,3,'2012-01-03' from dual union all
    select 3,1,4,'2012-01-04' from dual union all
    select 4,1,3,'2012-01-05' from dual union all
    select 2,3,2,'2012-01-07' from dual union all
    select 3,4,2,'2012-01-08' from dual union all
    select 4,3,1,'2012-01-09' from dual)
    --查询
    select a,b,c,count(1)
    from test2
    where d between '2012-01-04' and '2012-02-05'
    group by a,b,c
    --查询结果
    A       B       C       count
    4 1 3 1
    2 3 2 1
    4 3 1 1
    3 1 4 1
    3 4 2 1