SQL 总行数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4198619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:18:48  来源:igfitidea点击:

SQL total row count

sql

提问by ozsenegal

I need to select the number of rows:

我需要选择行数:

select 
    int_re_usu as Qtd_Respostas 
from 
    tb_questionario_voar_resposta  
group by 
    int_re_usu

It returns:

它返回:

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

I want to select instead the number 23,which is the total row_count.

我想选择数字 23,即总 row_count。

Any ideias?

有什么想法吗?

回答by John Hartsock

Use @@RowCount

使用@@RowCount

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

OR Use a Derived Table

或使用派生表

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

回答by thomaspaulb

Use COUNT():

使用COUNT()

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

回答by GendoIkari

Instead of GROUP BY, you can use DISTINCT:

您可以使用 DISTINCT 代替 GROUP BY:

SELECT COUNT(DISTINCT int_re_usu)
FROM tb_questionario_voar_resposta

回答by Lynette Duffy

With temp as 
( select int_re_usu as Qtd_Respostas 
  from tb_questionario_voar_resposta  
  group by int_re_usu )

Select count(*) from temp

回答by Ryan Guill

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

回答by Erkan Haspulat

You can use the count(*) function.

您可以使用 count(*) 函数。

select count(*) 
from table_name 
group by column_name