表head 字段year month cust_id cust_name ,things,gettime(收货准时,0表示不准时,1表示准时),
要求查询到这些数据的同时,显示另外一行为 小计 收货的准时率(即gettime为1的次数 除以 记录的条数)
急求各位sql达人帮忙
要求查询到这些数据的同时,显示另外一行为 小计 收货的准时率(即gettime为1的次数 除以 记录的条数)
急求各位sql达人帮忙
group by rollup (year,month,cust_id,cust_name)
select year,month,cust_id,cust_name,
nvl(gettime,sum(decode(gettime,1,1,0))/sum(1)) gettime from head
group by grouping sets((year,month,cust_id,cust_name,gettime),())
select 'b' a , 101 b, 0 c from dual union all
select 'c' a , 101 b, 1 c from dual )
select a ,b ,nvl(c,sum(decode(c,1,1,0))/sum(1)) c1
from ta group by
grouping sets((a,b,c),())
---------------------------------------------------
1 a 101 0
2 b 101 0
3 c 101 1
4 0.333333333333333
---------------------------------------------------
要么发数据,要么慢慢找。