我有3张桌子。我想在1个结果中选择 count ,例如:
table1=1000 records + table2=400 records + table3=200 records = 1600
1600
是我想从服务器返回的结果。
MySQL内联也许?有什么建议吗?
答案 0 :(得分:1)
select
(
select count(columnname) from table1
) + (
select count(columnname) from table2
)+ (
select count(columnname) from table3
)
答案 1 :(得分:1)
试试这个......,
SELECT (SELECT COUNT(*) FROM tbl1
)+
(SELECT COUNT(*) FROM tbl2
)+
( SELECT COUNT(*) FROM tbl3
) as 'AllCount'
答案 2 :(得分:0)
试试这个:
SELECT ((SELECT COUNT(*) FROM tbl1 ) + (SELECT COUNT(*) FROM tbl2 ) + (SELECT COUNT(*) FROM tbl3 )) AS TotalRecords
答案 3 :(得分:0)
select
((select count(*) from table1) + (select count(*) from table2) + (select count(*) from table3))
as totalCount;
答案 4 :(得分:0)
试试这个:
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
那将给你总数。
答案 5 :(得分:0)
谢谢大家的回复我有3个表,我想在1个单一结果中选择一个计数
我仍然得到这样的结果
count1 count2 count3 1235 134 234
,这不是我想要的总结果