select pro_id,unit_price from tbname where sale_date between '20041001' and '20041101'
group by pro_id,cunit_price having count(*)>1;
group by pro_id,cunit_price having count(*)>1;
解决方案 »
- Oracle 竖列如何横行现实
- 关于inner join
- oracle删除重复行剩一条记录
- 在sql检索数据的时候,就是where in语句,检索一个字段是肯定可以的.但能否用两个字段来做为in的条件
- 如何能够从动态SQL中返回新记录ROWID的值呢?
- 谁能用简短的话告诉我PL/SQL到底是指的什么?PL/SOL Development和ORACLE什么关系??
- 一个表的分区怎么单独脱机?在哪里可以查看到状态
- TNS 的一个怪问题。请教了!!!
- 如何找到表中重复的纪录(具体那个重复了)
- 一个排序的问题,请高手指教!!!
- 如何计算相邻行之间的最大差值(具体到里边看)
- 我都已经用nvl函数了,为何还是有ora-01400错误呢?
from t
where to_char(sale_date,'yyyymmdd')>='20041001'
and to_char(sale_date,'yyyymmdd')<='20041101'
and pro_id='1'
虽然进了一步,可是还是不行啊,一些符合条件的数据丢掉了,不符合的还存在。
还有,本来就只有一条的也不要显示的。
继续求教!
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
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;
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;
但是不明白你说的;“一些符合条件的数据丢掉了”
是不是这个意思,如果ID为1,那么要列出ID为一1的所有记录?
group by pro_id,cunit_price having count(*)>1;
这个没有问题
首先对大家表示感谢!
bzszp(SongZip)的方法只是统计出了同物品同价格出现大于1次的情况;
而我要的结果是同物品不同价格出现的情况,
并且只有一个价格时也不计算在内,
结果集应该是:在时间段内,出现过多个不同价格的物品信息(当然包括数量、价格、金额等);
目前几个方法好像都没能很好的解决这个问题,请大家继续关注!
谢谢!
---------- ---------- ---------- --------
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代替,那样速度快 ,楼主自己改改,我不说了
我在前面已经和你分析了你的需求,你看了没有啊?
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;
);
方法可行,调试成功!
谢谢各位。
qiaozhiwei(乔) 的方法比较简单可行,也在此特别感谢!