select w.*,
case when w.Bid in (select distinct WSe_Bid from WSend_phone) then '1' else '0' end as bianji,
(select top 1 sendflag from WSend_phone where WSe_Bid=w.bid ) as sendflag,
(select count(Recphone) from WSend_phone where WSe_Bid=w.bid ) as pcount from WSend_Business w表WSend_phone和表WSend_Business 是多对一的关系 ,WSend_phone 中的WSe_Bid 对应WSend_Business 中的bid列,
谢谢各位啦!
case when w.Bid in (select distinct WSe_Bid from WSend_phone) then '1' else '0' end as bianji,
(select top 1 sendflag from WSend_phone where WSe_Bid=w.bid ) as sendflag,
(select count(Recphone) from WSend_phone where WSe_Bid=w.bid ) as pcount from WSend_Business w表WSend_phone和表WSend_Business 是多对一的关系 ,WSend_phone 中的WSe_Bid 对应WSend_Business 中的bid列,
谢谢各位啦!
w.*,
CASE WHEN ws.Wse_Bid IS NULL THEN 0 ELSE 1 END AS bianji,
B.sendflag,B.pcount
FROM WSend_Business w
LEFT JOIN (SELECT WSe_Bid,COUNT(Recphone) AS pcount,MIN(sendflag) AS sendflag
FROM WSend_phone GROUP BY Wse_Bid) AS ws
ON w.bid = ws.Wse_Bid;--这样试试