sql (9) COUNT

COUNT() 函数返回匹配指定条件的行数。
语法
SQL COUNT(column_name) 语法
COUNT(column_name) 函数返回指定列的值的数目(NULL 不计入):
新建表
StudentS
S_id Grade Name phone
1 98 小明 123456
2 97 小黄 232456
3 95 小哩 987654
4 93 小小 654321
5 90 微微 321065
6 93 小小 654321
7 95 微微 321065
查询:
select count(Grade) as Gradecount from StudentS
where Grade=93
效果:
Gradecount
2
在表中有两行是分数为93的:
4 93 小小 654321
6 93 小小 654321


select count(Grade) as Gradecount from StudentS
where Grade=95
效果:
Gradecount
2
在表中有两行是分数为95的:
3 95 小哩 987654
7 95 微微 321065


select count(Name) as Namecount from StudentS
where Name=小明'
效果:
Namecount
1
在SturdentS表中名字为小明的行数为1:
S_id Grade Name phone
1 98 小明 123456


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

效果:
Namecount
2
在SturdentS表中名字为小明的行数为1:
S_id Grade Name phone

4 93 小小 654321

6 93 小小 654321

2018-04-27    15:00:15

猜你喜欢

转载自www.cnblogs.com/guangzhou11/p/8962475.html
今日推荐