现有采购记录。如
A          B       C                   D               E
1003 2006 1 250926.0000 32170.0000
1003 2006 2 66549.6000 8532.0000
1010 2006 1 12832.9800 26064.0000
1010 2006 2 17201.1100 15483.0000
1011 2006 1 4945.4000          3130.0000
1011 2006 2 8217.5800   5201.0000
1012 2006 1 11066.8335 153142.5500
1012 2006 2 25925.6590 1273981.8003
1017 2006 1 104.8000          5240.0000
1017 2006 2 2636.0000          210.0000
1020 2006 1 9745.2600   38253.0000
如果1003 中D列的总和在100000-200000之间,则列出
1003 2006 1 250926.0000 32170.0000
1003 2006 2 66549.6000 8532.0000
如果不在这个范围内,则不需要。
请问如何实现。

解决方案 »

  1.   

    select *
    from 采购记录
    where A in (select A
        from 采购记录
        group by A
        having sum(D) between 100000 and 200000)
      

  2.   

    select a,b,c,e,sum(d)  
    from  tab1
    group by a,b,c,e
    having sum(d)>=100000union all select a,b,c,e,sum(d)  
    from  tab1
    group by a,b,c,e
    having sum(d)<=200000