表A字段如下
month name income
月份 人员 收入
1 a 1000
2 a 2000
3 a 3000
要求用一个SQL语句(注意是一个)得到所有人(不区分人员)每个月及上月和下月的总收入
要求列表输出为
月份 当月收入 上月收入 下月收入
2 2000 1000 3000
SELECT
o. MONTH,
sum(o.income) AS cur,
(
SELECT
sum(t.income)
FROM
t5 t
WHERE
t. MONTH = (o. MONTH + 1)
GROUP BY
t. MONTH
) AS next,
(
SELECT
sum(t.income)
FROM
t5 t
WHERE
t. MONTH = (o. MONTH - 1)
GROUP BY
t. MONTH
) AS last
FROM
t5 o
GROUP BY
o. MONTH