根据A表的条件COUNT(a),根据B表的条件COUNT(b),且两个条件无交集,如何写?
SELECT
COUNT(CASE WHEN ds.XKDM='010000' AND ds.LWPSZJ='是' THEN 1 ELSE NULL END) AS LWPSZJCount,
COUNT(CASE WHEN lw.XKDM='010000' AND lw.YJSFLM='1' THEN 1 ELSE NULL END) AS LWSSCount,
COUNT(CASE WHEN lw.XKDM='010000' AND lw.YJSFLM='2' THEN 1 ELSE NULL END) AS LWBSCount
FROM T_DS ds, T_LW lw
inner join T_YJSFL yjsfl on lw.YJSFLM=yjsfl.YJSFLM
结果是错的,可是不知道该怎么写了,求高手
------解决方案--------------------
SQL code
select * from
(select *,COUNT(CASE WHEN ds.XKDM='010000' AND ds.LWPSZJ='是' THEN 1 ELSE NULL END) AS LWPSZJCount)
t1
,
(select *,COUNT(CASE WHEN lw.XKDM='010000' AND lw.YJSFLM='1' THEN 1 ELSE NULL END) AS LWSSCount,
COUNT(CASE WHEN lw.XKDM='010000' AND lw.YJSFLM='2' THEN 1 ELSE NULL END) AS LWBSCount)
t2
where
t1.YJSFLM=t2.YJSFLM