我的这个查询从 shipwynum 151513 的转售表中获取 6 条记录:-
select re.recdat,
re.resaleid,
IF (re.benownsal != '', owsal.ownshortnam, if ((re.grptypsal != '' &&
re.bogrpidsal != ''), if (bosal.bogrpshort != '', bosal.bogrpshort,
bosal.bogrpnam), cou1.nation)) as seller,
IF (re.benownpur != '', owpur.ownshortnam, if ((re.grptyppur != '' &&
re.bogrpidpur != ''), if (bopur.bogrpshort != '', bopur.bogrpshort,
bopur.bogrpnam), cou.nation)) as buyer,
re.benownpur,
re.grptyppur,
re.bogrpidpur,
re.statuscod,
re.showinob,
re.benownsal,
re.grptypsal,
re.bogrpidsal
from resale as re
left join owner as owpur on owpur.ownwynum = re.benownpur
left join owner as owsal on owsal.ownwynum = re.benownsal
left join bogroup as bopur on bopur.bogrpid = re.bogrpidpur
left join bogroup as bosal on bosal.bogrpid = re.bogrpidsal
left join country as cou on cou.coucod = re.buynation
left join country as cou1 on cou1.coucod = re.selnation
where re.shipwynum = '151513' and
re.deleted = 'N'
order by re.saltyp desc,
re.recdat
在这里,我添加了从上面查询 shipwynum 15153 获得的示例数据屏幕截图:-
当我添加限制子句时LIMIT 1
,它会获得我期望的第一个记录。但它只适用于一艘船有shipwynum = 151513。我想为每艘船获得第一个记录。
我所做的更改是为了获得每艘船的此类记录。
任何帮助将不胜感激。
谢谢。