在数据库中怎么求出表的数据,并能求出每列的总和怎么用SQL实...5
发布网友
发布时间:2024-02-08 03:18
我来回答
共1个回答
热心网友
时间:2024-03-02 02:48
我不知道你需要hour_id 的总数还是总和,下面用子查询可以求出hour_id 的和。
select sum(hour_id ) , count(hour_id ) from
(
select hour_id,
TICKET_FAMILY,
sum(case when hour_id in(10,11,12) then total_in else 0 end) as total_in,
sum(case when hour_id in(10,11,12) then total_out else 0 end) as total_out
from tmo_od_flow_stats_mg
where gathering_date between to_date('2015-01-05','yyyy-mm-dd') and to_date('2015-01-05','yyyy-mm-dd')
group by hour_id,
TICKET_FAMILY
) t