要把第二个count的值除以两个count加起来的值,怎么写
SELECT DISTINCT AREANAME, SUM(SHMSL2)/(SUM(SHMSL1)+SUM(SHMSL2)) OVER(PARTITION BY AREANAME) AS SHMSL
FROM (SELECT R.NAME
AREANAME,
COUNT (CASE WHEN TS.SHMSL = '0' THEN 1
ELSE NULL
END) SHMSL1 ,
COUNT (CASE WHEN TS.SHMSL = '1' THEN 1
ELSE NULL
END) SHMSL2
FROM T_XNJD_ITEM_SERVICES TS
left join T_SYS_REGION R on R.AREAID = TS.AREAID
GROUP BY R.NAME
,
TS.SHMSL)
GROUP BY AREANAME,SHMSL