本文主要是介绍SQL复杂查询 合并LBR和BAC两个表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
SQL语句为,
SELECT BD_LBR.id AS ID, lanid AS LanId, Side AS Side, IsSameNext AS IsSameNext, Color AS Color, Width AS Width, Length AS Length, Marking AS Marking, GeomWGS84 AS GeomWGS84,BD_LBR.id AS PermanentID, BD_LBR.GlobalId AS LbrGlobalId, 1 AS OrderNumber, Type AS liearType, SubType AS liearSubType, 0.0 AS Offset FROM BD_LBR UNION ALL SELECT bac.id AS ID, IFNULL(lbr.lanid, -1) AS LanId, IFNULL(lbr.side, -1) AS Side, 0 AS IsSameNext, 0 AS Color, 0 AS Width, bac.Length AS Length, bac.Marking AS Marking,bac.GeomWGS84 AS GeomWGS84,bac.id AS PermanentID, bac.GlobalId AS LbrGlobalId, bac.OrderNumber AS OrderNumber, 0 AS liearType, 0 AS liearSubType, bac.Offset AS Offset FROM BD_BAC bac LEFT JOIN BD_LBR lbr ON lbr.id = bac.lbrid;
结果为,
SQL语句为,
select bd_lbr.id as ID, lanid as LanId, Side as Side from bd_lbr
union all
select bac.id as ID, IFNULL(lbr.lanid, -1) as LanId, IFNULL(lbr.Side, -1) as Side from bd_bac bac left join bd_lbr lbr on bac.lbrid = lbr.id;
结果为,
这篇关于SQL复杂查询 合并LBR和BAC两个表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!