当QGIS中目前仅左侧或内部SQL连接可用时,我能否在表B中显示多余或缺失的行

问题描述 投票:0回答:1

我有两个表文件A和表B,我已将它们导入到Geopackage中,然后使用QGIS中的DB Manager进行连接,以提供输出,显示名称,电缆长度或几何形状在以下代码中发生了变化,]

Select a.name, A.cable_leng, a.geom, a.fid
     , case when a.name <> B.name and
                 a.cable_leng <> B.cable_leng
            then 'Cable Name and Length modified'
            when a.name <> B.name then 'Name'
            when a.cable_leng <> B.cable_leng then 'Cable Length Modified'
            when b.name is null then 'Deleted Cable'
       end Cables
      , case when a.geom <> B.geom then 'Geometry Modified'
            when a.geom = B.geom then 'No Geometry Changes'
       end Geometry
  from table_1 a
  inner join table_2 b
    on a.fid = b.fid

我对SQL output满意的链接图像中得到以下输出

示例数据example of data

但是我想知道我可以对查询进行哪些编辑,以显示两个表之间的行数可能不同时(多余或缺失)。从我已经完成的研究中,我可能需要进行正确的联接,但是QGIS DB Manager当前不提供这种联接,但是后来我考虑了表B中的行可能较少的情况。因此,我可能想显示在哪里左联接中的Table中是否有NULL值,还是应该使用其他查询类型?

作为旁注,有一种方法可以在输出中显示表A和表B中的数据。据我了解,无法对列在输出中的显示方式进行排序,但是,即使不能对它们进行排序,至少能够看到一个表中的不同值还是很不错的。

编辑:再次查看我的查询,此行可能没有用左联接执行任何操作?

when b.name is null then 'Deleted Cable'

[我有表A和表B,这是我导入到Geopackage中的两个shapefile,然后使用QGIS中的DB Manager进行连接以提供显示名称,电缆长度或...的位置的输出]]

sql join qgis
1个回答
0
投票

使用左连接您也可以从表_2中选择不匹配的行遵守表_1中的连接子句对于左联接,您可以检查缺少的匹配以检查是否为空值(例如,根据数据库的功能使用ifnull或类似的合并)对于比较中的其他数字,应将空值管理为0

    Select a.name, A.cable_leng, a.geom, a.fid
     , case when  a.cable_leng <> coalesce(B.cable_leng,0)
            then 'Cable Name and Length modified'
            when a.name <> coalesce(B.name, '')  then 'Name'
            when a.cable_leng <> coalesce(B.cable_leng,0) then 'Cable Length Modified'
            when b.name is null then 'Deleted Cable'
       end Cables
      , case when a.geom <> B.geom then 'Geometry Modified'
            when a.geom = B.geom then 'No Geometry Changes'
       end Geometry
  from table_1 a
  left  join table_2 b  on a.fid = b.fid
© www.soinside.com 2019 - 2024. All rights reserved.