MYSQL 总计数超过 1 table 总结果
MYSQL total count more than 1 table total result
我有 3 张桌子。我想在 1 个结果中 select count,例如:
table1=1000 records + table2=400 records + table3=200 records = 1600
1600
是我想要从服务器返回的一个结果。
也许是 MySQL 内部连接?有什么建议吗?
试试这个:
SELECT ((SELECT COUNT(*) FROM tbl1 ) + (SELECT COUNT(*) FROM tbl2 ) + (SELECT COUNT(*) FROM tbl3 )) AS TotalRecords
select
(
select count(columnname) from table1
) + (
select count(columnname) from table2
)+ (
select count(columnname) from table3
)
select
((select count(*) from table1) + (select count(*) from table2) + (select count(*) from table3))
as totalCount;
试试这个:
select sum(c) from (
select count(*) as c from table1
union
select count(*) as c from table2
union
select count(*) as c from table3
) tmp
这会给你总数。
试试这个...,
SELECT (SELECT COUNT(*) FROM tbl1
)+
(SELECT COUNT(*) FROM tbl2
)+
( SELECT COUNT(*) FROM tbl3
) as 'AllCount'
谢谢大家的回复我有 3 个表,我想 select 计算 1 个结果
我仍然得到这样的结果
count1 count2 count3
1235 134 234
这不是我想要的一共结果
我有 3 张桌子。我想在 1 个结果中 select count,例如:
table1=1000 records + table2=400 records + table3=200 records = 1600
1600
是我想要从服务器返回的一个结果。
也许是 MySQL 内部连接?有什么建议吗?
试试这个:
SELECT ((SELECT COUNT(*) FROM tbl1 ) + (SELECT COUNT(*) FROM tbl2 ) + (SELECT COUNT(*) FROM tbl3 )) AS TotalRecords
select
(
select count(columnname) from table1
) + (
select count(columnname) from table2
)+ (
select count(columnname) from table3
)
select
((select count(*) from table1) + (select count(*) from table2) + (select count(*) from table3))
as totalCount;
试试这个:
select sum(c) from (
select count(*) as c from table1
union
select count(*) as c from table2
union
select count(*) as c from table3
) tmp
这会给你总数。
试试这个...,
SELECT (SELECT COUNT(*) FROM tbl1
)+
(SELECT COUNT(*) FROM tbl2
)+
( SELECT COUNT(*) FROM tbl3
) as 'AllCount'
谢谢大家的回复我有 3 个表,我想 select 计算 1 个结果
我仍然得到这样的结果
count1 count2 count3 1235 134 234
这不是我想要的一共结果