-3

我需要instrn_id所有行都具有最大值的数据,我不能使用最大值,因为 t 只返回一行:

instrn_id ordr_id

599999  1659
599999  1659
599999  1659
599998  1633
599998  1633
599998  1633
599660  1659
599659  1633
599321  1659
599321  1659
599321  1659
599320  1633
599320  1633
599320  1633
598979  1659
598978  1633
598638  1659
598638  1659
598638  1659
598637  1633
598637  1633
4

3 回答 3

4

可能是这样的:

SELECT *
FROM _yourtable_
WHERE instr_id = (SELECT MAX(instr_id) from _yourtable_)
于 2013-11-04T13:30:44.500 回答
0
SELECT *
FROM 
_yourtable_ t1
JOIN
(SELECT MAX(instr_id) m FROM _yourtable_) t2
ON t1.instr_id  = m
于 2013-11-04T13:47:11.867 回答
0

这将在 mssql 中工作。我认为 oracle 具有相同的语法:

;with x as
(
select *, rank() over (order by ordr_id desc) rnk 
from <table>
) 
select instrn_id, ordr_id
from x
where rnk = 1
于 2013-11-04T14:06:49.320 回答