MySQL count函数的使用

count()函数在使用时参数好像不能设置为表达式,只能设置成指定字段或*

比如在查询性别为男的成员数目时不能写:

sql 复制代码
select count(gender='male') from user_profile ;

否则直接得到6,也就是等价于select count(gender) from user_profile ;

要查询指定字段带限制/条件时用where条件查询或者group by 分组查询:

sql 复制代码
select count(*) from user_profile where gender='male';
sql 复制代码
#分别得到男生和女生的人数
select count(*) as '人数',gender from user_profile group by gender;
相关推荐
last_zhiyin3 分钟前
Oracle sql tuning guide 翻译 Part 4-1 --- 连接操作(Joins)
数据库·sql·oracle
老华带你飞11 分钟前
农产品销售管理|基于springboot农产品销售管理系统(源码+数据库+文档)
数据库·vue.js·spring boot
电商API&Tina16 分钟前
跨境电商速卖通(AliExpress)数据采集与 API 接口接入全方案
大数据·开发语言·前端·数据库·人工智能·python
-suiyuan-17 分钟前
sqli-labs靶场1~2笔记
数据库·sql
瀚高PG实验室19 分钟前
在Highgo DB 中创建MySQL兼容函数datediff
数据库·mysql·瀚高数据库
bing.shao23 分钟前
FerretDB 替换MongoDB符合信创要求
数据库·mongodb
czlczl2002092531 分钟前
SpringBoot实践:从验证码到业务接口的完整交互生命周期
java·spring boot·redis·后端·mysql·spring
Han_coding120833 分钟前
从原理到实战:基于游标分页解决深分页问题(附源码方案)
java·服务器·数据库·spring boot·spring cloud·oracle
今晚务必早点睡1 小时前
Redis——快速入门第一课:了解redis
数据库·redis·缓存
今晚务必早点睡1 小时前
Redis——快速入门第三课:真实项目里的缓存完整流程
数据库·redis·缓存