简体   繁体   English

在一个查询中比较两个不同的查询输出

[英]compare two different output of queries in one query

I have two table which connected with each other Primary key - Foreign Key. 我有两个相互关联的表主键-外键。 I want to check their output are matching or not. 我想检查其输出是否匹配。

  1. Query :: 查询::

Select LINK_ID as A1, PHYSICAL_NUM_LANES as count1 from RDF_NAV_LINK where PHYSICAL_NUM_LANES is not null

RecNo    | A1           | count1
-----------------------------------
1        |51364636      |2
2        |51366793      |1
3        |51366795      |1
4        |51366796      |4
  1. Query :: 查询::

Select LINK_ID as A2, count(*) as count2 from RDF_LANE Group by LINK_ID

RecNo   |A2         |count2
----------------------------------
1       |51364636   |2
2       |51366793   |2
3       |53676455   |3
4       |53676460   |1

Now I want to check if A1 = A2 then count1 have to equals count2 (if not is my output) 现在我想检查A1 = A2,然后count1必须等于count2 (如果不是我的输出)

Join both your selects on A1 = A2 AND count1 <> count2 A1 = A2 AND count1 <> count2上同时加入两个选择

SELECT * FROM
(Select LINK_ID as A1, PHYSICAL_NUM_LANES as count1 from RDF_NAV_LINK where PHYSICAL_NUM_LANES is not null) X
INNER JOIN
(Select LINK_ID as A2, count(*) as count2 from RDF_LANE Group by LINK_ID) Y
ON A1 = A2 AND count1 <> count2;

Try like this 这样尝试

SELECT *
FROM
(
  (
   Select LINK_ID AS A1, PHYSICAL_NUM_LANES AS Count1 
   FROM RDF_NAV_LINK 
   WHERE PHYSICAL_NUM_LANES IS NOT NULL
  )S JOIN
  (
   Select LINK_ID AS A2, Count(*) As Count2 
   FROM RDF_LANE 
   GROUP BY LINK_ID
  )T ON T.A1 = S.A1 AND T.Count2 <> S.Count1
) Tmp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM