select pro_id,unit_price from tbname where sale_date between '20041001' and '20041101'
group by pro_id,cunit_price having count(*)>1;

解决方案 »

  1.   

    select * 
      from t
     where to_char(sale_date,'yyyymmdd')>='20041001'
       and to_char(sale_date,'yyyymmdd')<='20041101'
       and pro_id='1'
      

  2.   

    谢谢 bzszp(SongZip) :
    虽然进了一步,可是还是不行啊,一些符合条件的数据丢掉了,不符合的还存在。
    还有,本来就只有一条的也不要显示的。
    继续求教!
      

  3.   

    select A.pro_id,A.unit_price 
    from tbname A,tbname B
    where (A.sale_date between '20041001' and '20041101') and A.pro_id = B.pro_id and A.unit_price <> B.unit_price
      

  4.   

    select a.pro_id,count(a.pro_id) from (
    select pro_id,count(unit_price)
    from ww
    where sale_date>='20041001'
    and   sale_date<='20041101'
    group by pro_id,unit_price) a
    group by a.pro_id having count(a.pro_id)>1;
      

  5.   

    select a.pro_id,count(a.pro_id) from (
    select pro_id,count(unit_price)
    from table
    where sale_date>='20041001'
    and   sale_date<='20041101'
    group by pro_id,unit_price) a
    group by a.pro_id having count(a.pro_id)>1;
      

  6.   

    bzszp(SongZip)的方法应该可以啊.
      

  7.   

    我的语句可以帮你找出价格有变化的ID,
    但是不明白你说的;“一些符合条件的数据丢掉了”
    是不是这个意思,如果ID为1,那么要列出ID为一1的所有记录?
      

  8.   

    select pro_id,unit_price from tbname where sale_date between '20041001' and '20041101'
    group by pro_id,cunit_price having count(*)>1;
    这个没有问题
      

  9.   

    抱歉,来的晚了。
    首先对大家表示感谢!
    bzszp(SongZip)的方法只是统计出了同物品同价格出现大于1次的情况;
     
    而我要的结果是同物品不同价格出现的情况,
    并且只有一个价格时也不计算在内,
    结果集应该是:在时间段内,出现过多个不同价格的物品信息(当然包括数量、价格、金额等);
    目前几个方法好像都没能很好的解决这个问题,请大家继续关注!
    谢谢!
      

  10.   

    SQL> select * from ww;    PRO_ID UNIT_PRICE   QUANTITY SALE_DAT
    ---------- ---------- ---------- --------
             1        2.5         50 20041020
             1          3         60 20041030
             2          2        100 20041025
             2          2        300 20041030
             1          3         50 20041021SQL> select a.pro_id,count(a.pro_id) from (
      2  select pro_id,count(unit_price)
      3  from ww
      4  where sale_date>='20041001'
      5  and   sale_date<='20041101'
      6  group by pro_id,unit_price) a
      7  group by a.pro_id having count(a.pro_id)>1;    PRO_ID COUNT(A.PRO_ID)
    ---------- ---------------
             1               2SQL> select * from ww where pro_id in (
      2  select a.pro_id from (
      3  select pro_id,count(unit_price)
      4  from ww
      5  where sale_date>='20041001'
      6  and   sale_date<='20041101'
      7  group by pro_id,unit_price) a
      8  group by a.pro_id having count(a.pro_id)>1);    PRO_ID UNIT_PRICE   QUANTITY SALE_DAT
    ---------- ---------- ---------- --------
             1        2.5         50 20041020
             1          3         60 20041030
             1          3         50 20041021
    这里的 pro_id in可以用exists代替,那样速度快 ,楼主自己改改,我不说了
      

  11.   

    to flysky(剑舞飞天)
    我在前面已经和你分析了你的需求,你看了没有啊?
      

  12.   

    try:
    select * from tbname 
    where pro_id not in(select pro_id,unit_price from tbname where sale_date between '20041001' and '20041101'
    group by pro_id,cunit_price having count(*)>1;
    );
      

  13.   

    我用的表名是ww,你把我的语句里的ww改成你的表名即可
      

  14.   

    多谢 ATGC(这一生受了很多委屈吃了很多苦。。) !
    方法可行,调试成功!
    谢谢各位。
      

  15.   

    补充一下:
       qiaozhiwei(乔) 的方法比较简单可行,也在此特别感谢!