我的查询没有给我我想要的东西,
SELECT p.procid
, p.procdate
, p.vendor
, s.sup_name
, p.creditamount
, p.image
FROM procurement as p
, supplier as s
WHERE p.vendor = s.sid
GROUP
BY sid
ORDER
BY p.procid ASC
查询给了我表中每个供应商的第一个条目,而我想获取采购表中每个供应商的最后一个条目(所需的突出显示在图像中),任何输入将不胜感激,谢谢
答案 0 :(得分:1)
您可以使用相关的子查询
select t2.*,s.sup_name from
(
select t.* from procurement t
where t.procid in
(
select max(procid)
from procurement t1
where t1.vendor=t.vendor
)
) as t2 join supplier as s on t2.vendor = s.sid