2010-11-16 55 views
3

,我需要選擇行數:SQL總行數

select 
    int_re_usu as Qtd_Respostas 
from 
    tb_questionario_voar_resposta 
group by 
    int_re_usu 

它返回:

1- 687 
2- 375076 
3- 339012 
4 -314083 
5 -52741 
6 -339977 
7- 276041 
8- 373304 
9 - 339476 
10- 51095 
11- 270365 
12 - 6 
13 - 308670 
14 -305232 
15 - 85868 
16 - 9893 
17 -300598 
18 - 300572 
19 - 275889 
20 - 6092 
21 - 80092 
22 - 307104 
23 -273393 

我想,而不是選擇23號,這是總ROW_COUNT。

任何意識?

回答

4

使用@@行數

select int_re_usu as Qtd_Respostas from tb_questionario_voar_resposta group by int_re_usu 
Select @@RowCount 

或 使用派生表而不是GROUP BY的

Select Count(*) from 
(select int_re_usu as Qtd_Respostas from tb_questionario_voar_resposta group by int_re_usu) q1 
5

使用COUNT()

select COUNT(*) FROM (
    SELECT int_re_usu as Qtd_Respostas 
    from tb_questionario_voar_resposta 
    group by int_re_usu 
) 
+0

當然這並不完全...它返回我23行...我只想要一行,總行數 – ozsenegal 2010-11-16 20:32:56

+0

oops,你是對的。我糾正了它。 – thomaspaulb 2010-11-16 20:34:27

1
select count(*) from 
(select int_re_usu as Qtd_Respostas from tb_questionario_voar_resposta group by int_re_usu) as a 
1

可以使用COUNT(*)函數。

select count(*) 
from table_name 
group by column_name 
3

,你可以使用DISTINCT:

SELECT COUNT(DISTINCT int_re_usu) 
FROM tb_questionario_voar_resposta 
1
With temp as 
(select int_re_usu as Qtd_Respostas 
    from tb_questionario_voar_resposta 
    group by int_re_usu) 

Select count(*) from temp