求一个表的统计,分组 查询

qq_28548709 2016-06-13 07:17:27
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and t.cmplted_date is null group by t.cust_mana_id;--在途定单
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and t.is_assembly_ord = 1 group by t.cust_mana_id;--待装定单
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and (to_date(t.must_date, 'yyyy/mm/dd hh24:mi:ss')-t.cmplted_date) < 0 group by t.cust_mana_id;--全程超时
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and (to_date(t.limit_dt, 'yyyy/mm/dd hh24:mi:ss')-t.fnsh_dt) < 0 group by t.cust_mana_id;--环节超时
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and (to_date(t.must_date, 'yyyy/mm/dd hh24:mi:ss')-t.cmplted_date) < 7 group by t.cust_mana_id;--超7工作日
select t.cust_mana_id,count(*) as cou from iom_list_table t where t.cust_mana_id is not null and t.cmplted_date is not null group by t.cust_mana_id;--已完成定单

统计表 cust_mana_id,在途定单数,待装定单数,全程超时数,环节超时数,超7工作日数,已完成定单数 并按 cust_mana_id 分组 cust_mana_id 不能为空

就是按照上面的条件,再做一个分组,并把数据放到一个表中
...全文
94 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ylsss330 2016-06-14
  • 打赏
  • 举报
回复

select t.cust_mana_id,
sum(case when t.cust_mana_id is not null and t.cmplted_date is null then 1 else 0 end) as "在途定单",
sum(case when t.cust_mana_id is not null and t.is_assembly_ord = 1 then 1 else 0 end) as "待装定单",
sum(case when t.cust_mana_id is not null and (to_date(t.must_date, 'yyyy/mm/dd hh24:mi:ss')-t.cmplted_date) < 0  then 1 else 0 end) as "全程超时",
sum(case when t.cust_mana_id is not null and (to_date(t.limit_dt, 'yyyy/mm/dd hh24:mi:ss')-t.fnsh_dt) < 0 then 1 else 0 end) as "环节超时",
sum(case when t.cust_mana_id is not null and (to_date(t.must_date, 'yyyy/mm/dd hh24:mi:ss')-t.cmplted_date) < 7 then 1 else 0 end) as "超7工作日",
sum(case when t.cust_mana_id is not null and t.cmplted_date is not nullthen 1 else 0 end) as "已完成定单"
from iom_list_table t 
group by t.cust_mana_id
大概就这样把
z123zjf 2016-06-13
  • 打赏
  • 举报
回复
sum(case when xx 1 else 0 end)
qq_28548709 2016-06-13
  • 打赏
  • 举报
回复
自己顶一下。。。

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧