sql (9) COUNT

The COUNT() function returns the number of rows that match the specified criteria.
Syntax
SQL COUNT(column_name) Syntax
COUNT(column_name) The function returns the number of values ​​in the specified column (NULL is not counted):
New table
StudentS S_id
Grade Name phone
1 98 Xiao Ming 123456
2 97 Xiao Huang 232456
3 95 Xiao Li 987654
4 93 Xiao Small 654321
5 90 Pico 321065
6 93 Small 654321
7 95 Pico 321065
Query:
select count(Grade) as Gradecount from StudentS
where Grade=93
Effect:
Gradecount
2
has two rows in the table with a score of 93:
4 93 Small 654321
6 93 Little 654321


select count(Grade) as Gradecount from StudentS
where Grade=95
Effect:
Gradecount
2
has two rows in the table with a score of 95:
3 95 Xiaoli987654
7 95 Weiwei321065


select count(Name) as Namecount from StudentS
where Name=Xiao Ming'
effect:
Namecount
1
in SturdentS table, the number of rows named Xiao Ming is 1:
S_id Grade Name phone
1 98 Xiao Ming 123456

 


select count(Name) as Namecount from StudentS
where Name='小小'

Effect:
Namecount
2
in the SturdentS table, the number of rows named Xiaoming is 1:
S_id Grade Name phone

4 93 Little 654321

6 93 Little 654321

 

 

2018-04-27    15:00:15

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324964145&siteId=291194637