--工单数量
select SiteCity,COUNT(*) as CityOrderCount from WorkOrder where UserID is not null group by SiteCity
--已签收工单数量
select SiteCity,COUNT(*)as SigneOrderCount from WorkOrder where UserID is not null and State < 3 group by SiteCity
已知的工单数量和已签收工单数量已经用SQL语句写出,怎么用SQL语句来求签收率(=已签收工单数量/工单数量)?
Select SiteCity, sum(CityOrderCount) as CityOrderCount, sum(SigneOrderCount) as SigneOrderCount, sum(SigneOrderCount)/sum(CityOrderCount)
from
(select SiteCity,COUNT(*) as CityOrderCount, 0 as SigneOrderCount from WorkOrder where UserID is not null group by SiteCity
UNION ALL
select SiteCity,0, COUNT(*)as SigneOrderCount from WorkOrder where UserID is not null and State < 3 group by SiteCity)M
差不多是这样,细微处你自己调整下。
0 as SigneOrderCount from WorkOrder,,,,这样的话,SigneOrderCount这列的值变为0了还怎么求百分比
@怀挺FengL: 你先看懂再说吧,要不然上机测试下也行。
@爱编程的大叔: 已经测试过
同case when。。。 else。。。end 来做,这里可以用除法的