--结果表二
select a.*,row_number() over(partition by b.CASEA order by b.CASEA) NEWID,IsNull(b. CASEA,'') CASEA
from TABLE1 a
join TABLE2 b on a.GUID=b.PERSONID
order by a.GUID
------解决方案--------------------
------解决方案--------------------
SQL code
--结果表1
SELECT a.*,IsNull(b.CASEA,'') CASEA,IsNull(c.CASEB ,'')CASEB
FROM TABLE1 a
LEFT JOIN TABLE2 b
ON a.GUID=b.PERSONID
LEFT JOIN TABLE3 c
ON a.GUID=c.PERSONID
ORDER BY a.GUID
--结果表2
SELECT a.*,row_number() over (partition by A.GUID,A.NAME,B.CASEA order by A.GUID) as NEWID,IsNull(b.CASEA,'') AS CASEA,
FROM TABLE1 a
LEFT JOIN TABLE2 b
ON a.GUID=b.PERSONID
ORDER BY a.GUID