ITPub博客

首页 > 数据库 > Oracle > SQL语句集合

SQL语句集合

原创 Oracle 作者:football2006 时间:2008-07-10 19:20:04 0 删除 编辑

一、
表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)
)

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8119050/viewspace-1007092/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 修改Spfile的参数
请登录后发表评论 登录
全部评论
  • 博文量
    39
  • 访问量
    94129