我试图将三个查询合并为一个并且悲惨地失败。一切顺利,直到我通过"添加"顺序。子句。
SELECT
wti.price, hh.price, mb.price
FROM
spotprices.wti, spotprices.hh, spotprices.mb
ORDER BY
wti.sdate desc limit 1, hh.sdate desc limit 1, mb.sdate desc limit 1;
本质上,我试图通过sdate desc limit 1"使用"命令来获得sdate的最新价格。特技。单独地,查询效果很好。
SELECT price FROM spotprices.wti ORDER BY wti.sdate desc LIMIT 1;
答案 0 :(得分:1)
使用select
中的子查询:
SELECT (SELECT wti.price FROM spotprices.wti ORDER BY wti.sdate DESC LIMIT 1) as wti_price,
(SELECT hh.price FROM spotprices.hh ORDER BY hh.sdate DESC LIMIT 1) as hh_price,
(SELECT mb.price FROM spotprices.mb ORDER BY mb.sdate DESC LIMIT 1) as mb_price;