mysql 连接查询,如何得到总的记录条数

时间:2021-08-31 23:25:05
如果是一张表,我们可以通过

select  x1,x2,(select count(*) from xxtable) as count
from  xxtable

得到每次查询总共有多少条记录,我现在有两张表连接查询如下,我也想知道根据条件每次查询的总记录条数,着个sql语句怎么写??

select  a.x1,a.x2,b.x3,x4
from  xxtable1 as a,xxtable2 as b
where a.id=b.id and (orther conditions)

4 个解决方案

#1


select  a.x1,a.x2,b.x3,x4,(select count(*) from  xxtable1 as a1,xxtable2 as b1 where a1.id=b1.id and (orther conditions) ) as cout
from  xxtable1 as a,xxtable2 as b
where a.id=b.id and (orther conditions)

#2


该回复于2011-03-30 14:32:55被版主删除

#3


加2个
类似(select count(*) from xxtable) as count
的子句不就行了吗?

#4


select  a.x1,a.x2,b.x3,x4,(SELECT COUNT(*) FROM ... WHERE ...)
from  xxtable1 as a,xxtable2 as b
where a.id=b.id and (orther conditions)

#1


select  a.x1,a.x2,b.x3,x4,(select count(*) from  xxtable1 as a1,xxtable2 as b1 where a1.id=b1.id and (orther conditions) ) as cout
from  xxtable1 as a,xxtable2 as b
where a.id=b.id and (orther conditions)

#2


该回复于2011-03-30 14:32:55被版主删除

#3


加2个
类似(select count(*) from xxtable) as count
的子句不就行了吗?

#4


select  a.x1,a.x2,b.x3,x4,(SELECT COUNT(*) FROM ... WHERE ...)
from  xxtable1 as a,xxtable2 as b
where a.id=b.id and (orther conditions)