表A字段id,name
表B字段id,content
现在要查询查表A的记录总数,条件是A.id=B.id 并且表B对应的记录条数为0,在线等了....
类似SELECT COUNT(*)
FROM tb1,tb2
WHERE tb1.id=tb2.id AND b.recordcount=0 这样的是完全错的....因为recordcount不能在sql直接这样运行...
在线等...
表B字段id,content
现在要查询查表A的记录总数,条件是A.id=B.id 并且表B对应的记录条数为0,在线等了....
类似SELECT COUNT(*)
FROM tb1,tb2
WHERE tb1.id=tb2.id AND b.recordcount=0 这样的是完全错的....因为recordcount不能在sql直接这样运行...
在线等...
from A
where not exists(select * from B where A.id=B.id)
--这样吗?
SELECT COUNT(*) FROM A WHERE ID NOT IN(SELECT ID FROM B)
select count(*)
from tb1 A
where not exists(select * from tb2 B where A.id=B.id)
FROM tb1,tb2
WHERE tb1.id=tb2.id AND b.recordcount=0
1 SELECT COUNT(*)
FROM A
WHERE ID NOT IN(SELECT ID FROM B)2 select count(*)
from A
where not exists(select * from B where A.id=B.id)
2的效率高於1