求一个sql语句
id number sth tosb
-------------------------------
1 20 XXX.. a
2 10 YYY.. a
3 13 ZZZ.. b
4 7 KKK.. b
5 19 PPP.. a
从表table里选择出对于同一个tosb,number最大的那个数据的sth,既
tosb number sth
-------------------------
a 20 XXX..
b 13 ZZZ..
SQL code:
select *
from tb t
where
not exists(select 1 from tb where tosb=t.tosb and number>t.number)
SQL code:
select * from tb
t where not eixsts(select 1 from tb where tosb=t.tosb and number>t.number)
select
tosb , number , sth
from tb t
where not exists
(
select * from tb where t.tosb=tosb and t.number <number
)
SQL code
Code highlighting produced by Acti
相关问答:
大家帮忙看看这2个sql语句哪个查询的速度更快点。谢谢帮忙。比较着急。在做性能测试。
select * from
表A LEFT OUTER JOIN 表B ON (表A.id || ' ' =表B.id) ,表C , 表D, 表E
Where其他条件
select * ......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
需求如下:
a表:
p_id status
1 0
2 0
b表
rec_id pid purchase_qty receive_qty flag
1 1 10 10 0
2 ......