如何删除表中的空行?
我编写了一个查询,以连接来自不同表的几列(有效)。但是,我想删除表格底部的许多空行。
SELECT
s.Name_of_owner,
s.pos,
s.Orientation,
isnull(s.DBName,z.DBName) DBName,
isnull (s.Name,z.Name) Name,
isnull (s.Refno,z.Refno) Refno,
isnull (s.Type_,z.Type_) Type_,
isnull (s.Desc_,z.Desc_) Desc_,
isnull (s.mcount, z.mcount) mcount,
z.Name_of_Site,
z.Desc_of_Site
FROM SITE s
FULL OUTER JOIN ZONE z ON z.Name = s.Name
FULL OUTER JOIN SITE ON z.DBName = s.DBName
答案 0 :(得分:0)
使用INNER JOIN
作为inner join
匹配现有值的表:
SELECT
s.Name_of_owner,
s.pos,
s.Orientation,
isnull(s.DBName,z.DBName) DBName,
isnull (s.Name,z.Name) Name,
isnull (s.Refno,z.Refno) Refno,
isnull (s.Type_,z.Type_) Type_,
isnull (s.Desc_,z.Desc_) Desc_,
isnull (s.mcount, z.mcount) mcount,
z.Name_of_Site,
z.Desc_of_Site
FROM SITE s
INNER JOIN ZONE z ON z.Name = s.Name
INNER JOIN SITE ON z.DBName = s.DBName
答案 1 :(得分:0)
只需使用WHERE
过滤器:
SELECT
s.Name_of_owner,
s.pos,
s.Orientation,
isnull(s.DBName,z.DBName) DBName,
isnull (s.Name,z.Name) Name,
isnull (s.Refno,z.Refno) Refno,
isnull (s.Type_,z.Type_) Type_,
isnull (s.Desc_,z.Desc_) Desc_,
isnull (s.mcount, z.mcount) mcount,
z.Name_of_Site,
z.Desc_of_Site
FROM
SITE s
FULL OUTER JOIN ZONE z ON z.Name = s.Name
FULL OUTER JOIN SITE ON z.DBName = s.DBName
WHERE
s.Name_of_owner IS NOT NULL
如果要确保所有列都不是NULL
,则必须编写一堆AND
过滤器:
SELECT
s.Name_of_owner,
s.pos,
s.Orientation,
isnull(s.DBName,z.DBName) DBName,
isnull (s.Name,z.Name) Name,
isnull (s.Refno,z.Refno) Refno,
isnull (s.Type_,z.Type_) Type_,
isnull (s.Desc_,z.Desc_) Desc_,
isnull (s.mcount, z.mcount) mcount,
z.Name_of_Site,
z.Desc_of_Site
FROM
SITE s
FULL OUTER JOIN ZONE z ON z.Name = s.Name
FULL OUTER JOIN SITE ON z.DBName = s.DBName
WHERE
s.Name_of_owner IS NOT NULL AND
s.pos IS NOT NULL AND
(S.DBName IS NOT NULL OR z.DBName IS NOT NULL) AND -- isnull(s.DBName,z.DBName)
-- ....
请记住,您正在使用FULL JOIN
,因此可能会有完整的表在它们不匹配时产生NULL
值。因此,强制对特定列(来自特定表)的过滤器可能从其他“完全联接”表中删除行。您可以进行OR
过滤器来检查多个表中的值(如本例所示)。