sql中join与left-join图解区别
select a.* from YG_BRSYK a left join(SELECT DISTINCT SYXH, STUFF((SELECT '、'+MS FROM #lsb where SYXH=t.SYXH FOR XML PATH('')),1,1,'') AS MS FROM #lsb as t) c on a.SYXH=c.SYXH WHERE c.MS IS NOT NULL order by RYBQ
--注:left join...on 为左关联,保留左边所有的数据,右表没有的数据为NULL值。加where条件控制表的输出C.MS不为NULL。因此查询的个数与c表一致760个
select a.* from YG_BRSYK a --801331个
SELECT DISTINCT SYXH,
STUFF((SELECT '、'+MS FROM #lsb where SYXH=t.SYXH FOR XML PATH('')),1,1,'') AS MS
FROM #lsb as t 670个
https://www.cnblogs.com/lcs-java/articles/8465605.html