在SQL中,如何计算UNION的结果?

时间:2013-05-16 11:56:57

标签: sql count union

假设我有一个查询,例如

SELECT * from frequency where (...) 
UNION 
SELECT * from frequency where  (...)

如何计算从上面返回的结果数量?

2 个答案:

答案 0 :(得分:5)

COUNT()函数与子查询一起使用

SELECT COUNT(*) AS Row_Counts
FROM 
(
  SELECT * from frequency where (...) 
  UNION 
  SELECT * from frequency where  (...)
) A

答案 1 :(得分:1)

为什么UNION?如果你结合WHERE条款,你可以这样计算:

SELECT COUNT(*)
FROM frequency 
WHERE (...) OR (...)