如何计算返回非常大的数据集的查询中的记录数?

时间:2013-11-07 18:18:09

标签: sql oracle

我有一个查询可以访问多个表并返回大量记录。但是,我无法滚动到底部并获取行号以查看有多少条记录。我怎么能只返回一行结果中的记录数?

我尝试将其全部放入' FROM'声明,但只有错误...更新因为&#34 ;;"是里面最后")" ... GAH !!!。

select T1.col-1, T1.col-2, T1.col-3, sum(T1.col-4), sum(T2.col-1), T2.col-2
from T1, T2
where T1.inedx-1=T2.inedx-1
group by T1.col-1, T1.col-2, T1.col-3, T2.col-2
order by T2.col-2

2 个答案:

答案 0 :(得分:4)

如果在查询周围放置SELECT COUNT(*),它将返回记录数:

SELECT COUNT(*)
FROM (
  SELECT T1.col - 1, T1.col - 2, T1.col - 3, sum(T1.col - 4), sum(T2.col - 1), T2.col - 2
  FROM T1, T2
  WHERE T1.inedx - 1 = T2.inedx - 1
  GROUP BY T1.col - 1, T1.col - 2, T1.col - 3, T2.col - 2
  ) a

ORDER BY您不需要COUNT

答案 1 :(得分:2)

select count(*) from (

    select T1.col-1, T1.col-2, T1.col-3, sum(T1.col-4), sum(T2.col-1), T2.col-2
    from T1, T2
    where T1.inedx-1=T2.inedx-1
    group by T1.col-1, T1.col-2, T1.col-3, T2.col-2
    order by T2.col-2

)

或者,我认为解释计划包括估计的行:

explain select T1.col-1, T1.col-2, T1.col-3, sum(T1.col-4), sum(T2.col-1), T2.col-2
from T1, T2
where T1.inedx-1=T2.inedx-1
group by T1.col-1, T1.col-2, T1.col-3, T2.col-2
order by T2.col-2