我在postrges中获得以下数据
id| count1 count2
12 3 0
12 0 2
但我想要综合结果
我从中获得结果
的查询SELECT
date_part( 'day', t1.requested_datetime ) AS requested_day,
CASE
WHEN date_part ( 'hour', t1.requested_datetime ) >= 0 AND date_part ( 'hour', t1.requested_datetime ) <= 11 THEN count ( date_part ( 'day', t1.requested_datetime ) )
ELSE 0
END AS count_am,
CASE
WHEN date_part ( 'hour', t1.requested_datetime ) > 11 AND date_part ( 'hour', t1.requested_datetime ) <= 23 THEN count ( date_part ( 'day', t1.requested_datetime ) )
ELSE 0
END AS count_pm
FROM
table1 t1
WHERE
date_part ( 'month', t1.requested_datetime ) = 11
AND date_part ( 'year', t1.requested_datetime ) = 2013
GROUP BY
requested_day,
date_part ( 'hour', t1.requested_datetime )
ORDER BY
date_part ( 'day', t1.requested_datetime )
预期结果
id count1 count2
12 3 2
请帮忙 感谢
答案 0 :(得分:0)
select id,
sum(count1) as count1,
sum(count2) as count2
from your_table
group by id