永发信息网

在数据库中怎么求出表的数据,并能求出每列的总和怎么用SQL实现呢?

答案:1  悬赏:40  手机版
解决时间 2021-02-15 21:32
  • 提问者网友:难遇难求
  • 2021-02-15 07:58
在数据库中怎么求出表的数据,并能求出每列的总和怎么用SQL实现呢?
最佳答案
  • 五星知识达人网友:春色三分
  • 2021-02-15 08:54
我不知道你需要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追问不是这个
我是想在total_out后面加一列来计算出total_in和total_out的和怎么加呢?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯