Php 如何使用mysql5中的查询添加不同查询的计数?

Php 如何使用mysql5中的查询添加不同查询的计数?,php,mysql,performance,mysql5,Php,Mysql,Performance,Mysql5,嗨,我需要一个这样的问题 select count(id) from employee where.. => gives count1=10 select count(id) from emplyer where.. => gives count2=5 select count(id) from users where.. => gives count3=20 count = count1+count2+count3; 从员工中选择计数(id),其中..=>给出cou

嗨,我需要一个这样的问题

select count(id) from employee where.. => gives count1=10 select count(id) from emplyer where.. => gives count2=5 select count(id) from users where.. => gives count3=20 count = count1+count2+count3; 从员工中选择计数(id),其中..=>给出count1=10 从emplyer中选择计数(id),其中..=>给出计数2=5 从用户中选择计数(id),其中..=>给count3=20 我可以这样添加这些结果

select count(id) from employee where.. => gives count1=10 select count(id) from emplyer where.. => gives count2=5 select count(id) from users where.. => gives count3=20 count = count1+count2+count3; 计数=计数1+计数2+计数3; 但我想知道是否有任何选项使用单个查询获取计数,而不是单独添加这些结果。此外,我想知道哪一个是最好的方式在应用程序性能的情况下

你能行

SELECT ((select count(id) from employee where..) + (select count(id) from emplyer where..) + (select count(id) from users where..))
几乎不会有性能差异-添加三个整数对MySql和php引擎都不是挑战。

您可以这样做

SELECT ((select count(id) from employee where..) + (select count(id) from emplyer where..) + (select count(id) from users where..))

几乎不会有性能差异-添加三个整数对MySql和php引擎都不是挑战。

如果使用group by子句,可以添加ROLLUP选项,该选项将返回组中所有计数的总和。请参阅如果使用group by子句,则可以添加带有ROLLUP的选项,该选项将返回组中所有计数的总和。请参见

对不起。。不仅有加法运算,而且还有三个以上的查询用于获取该计数值,这些查询不是简单的获取查询。所以我问了关于性能的问题。。不仅有加法运算,而且还有三个以上的查询用于获取该计数值,这些查询不是简单的获取查询。所以我问了性能