请在下面的代码中尝试此操作
SELECT
t.pc,
t.trans_date,
(
SELECT SUM(x.sale) FROM tbl_sample x
WHERE x.id <= MAX(t.id) AND t.pc = x.pc
-- Just used MAX(t.id) in place of t.id
-- As group by is available in the query
) -
SUM(sale) AS accum_sales_beginning,
SUM(sale),
(
SELECT SUM(x.sale) FROM tbl_sample x
WHERE t.pc = x.pc AND x.id <= MAX(t.id)
-- Just used MAX(t.id) in place of t.id
-- As group by is available in the query
) AS accum_sales_ending
FROM tbl_sample t
WHERE t.trans_date BETWEEN '2019-08-27' AND '2019-08-29'
AND t.pc = 'p1'
GROUP BY t.pc,t.trans_date;