select min(date),no , Q FROM test group by no,q
解决方案 »
- sql 2005转 oracle出错
- /*+rule*/
- 在做impdp时候,发生ora-39125异常
- 如何调试存储过程和package
- 更新一列的内容至另一列
- oracle 存储过程插入数据的问题?
- 清囊求教一个简单的问题(可怜可怜吧)
- 急:PL/SQL中的按位处理(and\or\xor)问题。
- 如何移动表空间文件移到另一个分区
- pl/sql数据库怎么向查出来的表中的列添加数据?求解!急!
- 用SQL怎么查一段时间内的数据,比如:2004-05至2004-09月的数据,date类型不能用<或>的,该用什么判断啊??
- ■■■■■■■■一个超级复杂的SQL语句,请问如何优化精简为简单一些的句子?■■■■■■■■■■
min(a.DATE) as DATE,
a.NO,
a.Q
from
test a
where
not exists(select * from test where DATE>=a.DATE and NO=a.NO and Q<>a.Q)
group by
a.NO,a.Q
2 select to_char(date1,'yyyy/mm/dd') "date",no,q,
3 row_number() over(partition by no order by date1 desc) rn1
4 from
5 (select t.*,row_number() over(partition by no,q order by date1) rn
6 from test t
7 ) where rn = 1
8 ) where rn1 = 1
9 /date NO Q RN1
---------- ---------- ---------- ----------
2005/07/16 001 7 1
2005/07/17 002 6 1
2005/07/17 003 2 1
2 select to_char(date1,'yyyy/mm/dd') "date",no,q,
3 row_number() over(partition by no order by date1 desc) rn1
4 from (select min(date1) date1,no ,Q FROM test group by no,q)
5 ) where rn1 = 1
6 /date NO Q RN1
---------- ---------- ---------- ----------
2005/07/16 001 7 1
2005/07/17 002 6 1
2005/07/17 003 2 1
select min(date),no , Q FROM test group by no,q==>select max(date),no , Q FROM test group by no,q