Oracle SQL:仅返回最大值

时间:2015-11-23 10:16:54

标签: sql oracle

以下查询结果为2行。我添加了最后一个'和'语句,以便仅显示高度为最大高度的结果,但报告仍返回2行?

select ds.catnr, pd.part_no, pd.description, ds.packtyp, pd.qty_box, ds.planqty, ds.weight_g, 
round((ds.planqty/pd.qty_box),'1') X, bom.av_part_no, lg.height, lg.length, lg.spine width, lg.part_no, lg.description
from oes_delsegview ds, part_description pd, 
TABLE(leos_flatbom_pkg.GetFlatBOM(pd.part_no)) bom, 
leos_gen_part_picture lg
where ds.ordnr = '0021565475'
and ds.posnr = '00002'
and ds.segnr = '001'
and ds.catnr = pd.catnr
and ds.prodtyp = pd.prodtyp
and ds.packtyp = pd.packtyp
and bom.prodtyp = 'KT'
and bom.av_part_no = lg.part_no
and lg.height = (select max(lg1.height) from leos_gen_part_picture lg1 where lg.part_no = lg1.part_no)

为什么'height = max(height)'不限制我的结果?如何更改脚本以仅显示'height = max(height)'的行?

当前结果......

enter image description here

必填结果......

enter image description here 感谢

1 个答案:

答案 0 :(得分:2)

没有数据我无法确定,但我建议

1)您在最大值上没有与查询的其余部分相同的条件

2)有两行具有相同的高度