我试图根据月份的值找到表中的金额总和。这是我的查询
SELECT to_char(
to_timestamp(
date_part('month', p.date_from)::text,
'MM'
),
'Month'
) as Month,
p.employee_id, p.id as payslip_id,
p.date_from, p.date_to, pl.amount
FROM hr_payslip p
INNER JOIN hr_payslip_line pl
ON (p.id = pl.slip_id AND pl.code = 'NET');
输出:
需要:
我需要按月份和列金额的总和进行分组。
答案 0 :(得分:1)
也许你只想要一个简单的GROUP BY
:
SELECT to_char(p.date_from, 'Month') as month,
sum(pl.amount)
FROM hr_payslip p
INNER JOIN hr_payslip_line pl
ON (p.id = pl.slip_id AND pl.code = 'NET')
GROUP BY to_char(p.date_from, 'Month');
答案 1 :(得分:0)