gpt4 book ai didi

来自 Recordset 的 MySQL 列

转载 作者:行者123 更新时间:2023-11-29 00:13:33 26 4
gpt4 key购买 nike

也许我看错了这一切。我有这张表,价格。当我报告新价格时,它会进入表格并具有类型、价格、stationid 和日期。我可以得到结果,但我想在列中列出 stationid 和不同的燃料类型及其价格。

这是一个示例表 http://sqlfiddle.com/#!2/8c04c/1

这就是我要的,每行每站的最新价格:

---------------------------------------------------------------------------------------------------------------------------------
stationid | regular | regDateAdded | midgrade | midDateAdded | premium | preDateAdded
---------------------------------------------------------------------------------------------------------------------------------
52775 | 3.61 | 0000-00-00 00:00:00 | 3.71 | 0000-00-00 00:00:00 | 3.81 | 0000-00-00 00:00:00

也许我也想多了。

最佳答案

虽然这可能会导致联系(如果多个站点共享相同的最大添加日期),但这是使用 max 聚合将表与其自身连接的常用方法:

select p.stationid, p.price, p.fueltypeid, p.dateadded
from prices p
join (select stationid, max(dateadded) maxdateadded
from prices
group by stationid) p2 on
p.stationid = p2.stationid and p.dateadded = p2.maxdateadded

关于来自 Recordset 的 MySQL 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23791099/

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