2010-12-16 48 views

回答

4

你应该使用UNION ALL来结合相同的值计数,如30 + 30。

select SUM(n) as total 
from (
    (select count(*) as n from table1) 
    UNION ALL 
    (select count(*) as n from table2) 
) t; 
1
select sum(num) as total 
from (
    (select count(*) as num from table1) 
    UNION ALL 
    (select count(*) as num from table2) 
) a; 
+0

如果两个子查询返回30,它不会返回60,而不是将返回30 – Pentium10 2010-12-16 06:39:13

+0

确实如此。感谢那。我会改正......虽然你已经发布了自己的答案,但我明白了。 – Lee 2010-12-16 06:42:42

+0

@Pentium,正如上面提到的评论,什么是修复如果两个子查询返回30,它不会返回60,而将返回30 – gmhk 2010-12-16 07:43:36

相关问题