1

我有一个查询命中几个表并将返回大量记录。但是,我不能只滚动到底部并获取行号以查看有多少记录。我怎样才能让它只返回一行结果中的记录数?

我试着把它全部放在一个'FROM'语句中,但这只会出错......更新因为“;” 在最后一个“)”......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
4

2 回答 2

4

如果您SELECT COUNT(*)在查询周围加上 a ,它将返回记录数:

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

于 2013-11-07T18:20:48.877 回答
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
于 2013-11-07T18:20:06.037 回答