cyw521
梦一场丶
2017-12-13 09:59

sql连表查询,查询A中数据B中是否存在

5
  • select
  • 去重复
  • sql

SELECT
o. ID AS ID,
(
CASE
WHEN q.uniscid = o.uniscid THEN
q.uniscid
ELSE
NULL
END
) AS uniscid,
(
CASE
WHEN q.regno = o.regno THEN
q.regno
ELSE
NULL
END
) AS regno,
(
CASE
WHEN q.entname = o.entname THEN
q.entname
ELSE
NULL
END
) AS entname
FROM
data_syfr_tem o
LEFT JOIN data_qyfr q ON (
o.entname = q.entname
OR o.uniscid = q.uniscid
OR o.regno = q.regno
)
WHERE
o.batchno = '20171213-2'
AND STATE = '1';


图片说明
我想把下面的2个6077合成 这种数据》》6077 1211 null 测试单位名称
有大哥能指点下吗?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

10条回答