当前的 SELECT 查询
SELECT a.*, ROUND(((a.avg-b.avg)/b.avg)*100,2) pct_change
FROM
(
SELECT x.*, COUNT(*) rank
FROM blavg x
JOIN blavg y
ON y.bline_id = x.bline_id
AND y.id >= x.id
GROUP BY x.id
) a
JOIN
(
SELECT x.*, COUNT(*) rank
FROM blavg x
JOIN blavg y
ON y.bline_id = x.bline_id
AND y.id >= x.id
GROUP BY x.id
) b
ON b.bline_id = a.bline_id
AND b.rank = a.rank+1
WHERE a.rank = 1;
我也想
SELECT bl_id, bline FROM bl
bl.bl_id = blavg.bline_id
我试过了
SELECT bl_id, bline
FROM bl bl
LEFT JOIN ON bl.bl_id = blavg.bline_id
但不确定我是否有正确的语法,我不确定在哪里添加ON
以及括号 () 去了哪里。
任何帮助将不胜感激。