gpt4 book ai didi

mysql - 从表中获取最新日期及其在mysql中的行

转载 作者:行者123 更新时间:2023-11-29 06:48:30 25 4
gpt4 key购买 nike

我有 2 个表: Assets 库存

表格资源

enter image description here

表库存

enter image description here

当我运行以下 mysql 查询时:

SELECT a.assetnum,a.description,a.user,MAX(b.invdate) as invdate , b.note 
FROM asset a
LEFT JOIN inventory b on a.assetnum=b.assetnum
GROUP BY a.assetnum, a.description

我得到的是这样的:

enter image description here

但是,应该是这样的......

enter image description here

我的 mysql 查询出了什么问题?有人可以帮我吗...

最佳答案

您基本上会在结果中得到一个随机的注释。您可能需要这样的东西:

 select a.assetnum,a.description,a.model, i.invdate, i.note 
from inventory i
join
(
select assetnum, max(invdate) max_invdate
from inventory
group by assetnum
) t on i.assetnum = t.assetnum and
i.invdate = t.max_invdate
right join asset a on a.assetnum = i.assetnum

关于mysql - 从表中获取最新日期及其在mysql中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48458465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com