【select语句】SQL语句理解select*fromBwhere(selectcount(1)asnumf...

发布时间:2021-04-03 01:04:10

SQL语句理解 select * from B where (select count(1) as num from A where A.ID = B.ID) = 0select * from B where (select count(1) as num from A where A.ID = B.ID) = 0请问如何理解,为什么 可以在B表中 排除A表的数据

网友回答

【答案】 子查询中select count(1) as num from A where A.ID = B.ID
  就是统计B表和A表用ID连接的行数
  子查询的行数=0,就可以实现从B表中排除A表数据 追问: 子查询只是把计数传过去啊 主查询如何得知具体数据行? 追答: nono, 这么看: select * from B where ?= 0 where中条件其实是,什么等于0? 代入 (select count(1) as num from A where A.ID = B.ID) 就是A和B通过ID连接后,COUNT(*)计数=0 追问: select count(1) as num from A where A.ID = B.ID 不等于0啊
以上问题属网友观点,不代表本站立场,仅供参考!