一、
表table中的数据如下:
有3个字段:
字段a 字段b 字段c
1 11 4
1 12 5
1 13 6
2 21 7
2 22 8
2 23 9
3 31 10
...
问题:
如何取得:字段a对应的最大字段b的记录,具体如下:
1 13 6
2 23 9
SQL:
select a,b,c from table where b in (select max(b) from table group by a);
或:
select u.a, u.b, u.c
from (select rowber_number() over(partition by a order by b desc) rn,
a.a,
a.b.a.c table a) u
where u.rn = 1
二、
select fid from t_st_weighnoticebillentryqi where fnumber in
(
select * from
(select fnumber from t_st_weighnoticebillentryqi t where to_char(t.fbizdate,'yyyy/mm/dd hh24:mi:ss') > '2008/06/15 07.13.52' and
to_char(t.fbizdate,'yyyy/mm/dd hh24:mi:ss') < '2008/07/01 07.13.52'
and t.fmaterialid = 'MPwdnwEQEADgB2cNwKgyAkQJ5/A='
minus
select substr(fsoucebillnumber,1,15) from t_st_qireportentry)
)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8119050/viewspace-1007092/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8119050/viewspace-1007092/