SELECT * FROM temp.CUST_NO ,temp.c,temp1.c1,temp2.c2
(SELECT CUST_NO,COUNT(*) c FROM CUST_DRAFTNO WHERE DRAFT_TYPE IN ('3','4','5')AND STATUS IN ('4','5') GROUP BY CUST_NO) temp
LEFT JOIN (SELECT CUST_NO,COUNT(*)c1 FROM CUST_DRAFTNO WHERE DRAFT_TYPE IN ('3','4','5')AND STATUS IN ('4','5') AND STATUS='4' GROUP BY CUST_NO) temp1 ON temp.CUST_NO=temp1.CUST_NO
LEFT JOIN (SELECT CUST_NO,COUNT(*) c2 FROM CUST_DRAFTNO WHERE DRAFT_TYPE IN ('3','4','5')AND STATUS IN ('4','5') AND STATUS='5' GROUP BY CUST_NO) temp2 ON temp.CUST_NO=temp2.CUST_NO
查出根据CUST_NO分组 的sql组成表
在使用LEFT JOIN 查出根据CUST_NO分组并且条件STATUS=4的sql组成表
继续使用LEFT JOIN 查出根据CUST_NO分组并且条件STATUS=5的sql组成表
组合查出的数据就是你要的
使用子查询,
SELECT (SELECT COUNT(*) FROM CUST_DRAFTNO CD WHERE CD.STATUS IN ('4','5') AND CD.CUST_NO=CDINFO.CUST_NO) COUNT1 FROM CUST_DRAFTNO CDINFO WHERE CDINFO.CUST_NO='11111'
OK
使用子查询,
SELECT(SELECT COUNT(*)FROM CUST_DRAFTNO CD,WHERE CD.STATUS('4','5')和CD.CUST_NO = CDINFO.CUST_NO的)COUNT1从CUST_DRAFTNO CDINFO,CDINFO.CUST_NO =“ 11111“
OK