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;
相关推荐
tokepson2 小时前
Mysql下载部署方法备份(Windows/Linux)
linux·服务器·windows·mysql
nbsaas-boot4 小时前
SQL Server 存储过程开发规范(公司内部模板)
java·服务器·数据库
zgl_200537794 小时前
ZGLanguage 解析SQL数据血缘 之 Python + Echarts 显示SQL结构图
大数据·数据库·数据仓库·hadoop·sql·代码规范·源代码管理
acaad4 小时前
Redis下载与安装(Windows)
数据库·redis·缓存
玄〤4 小时前
黑马点评中 VoucherOrderServiceImpl 实现类中的一人一单实现解析(单机部署)
java·数据库·redis·笔记·后端·mybatis·springboot
SunflowerCoder5 小时前
EF Core + PostgreSQL 配置表设计踩坑记录:从 23505 到 ChangeTracker 冲突
数据库·postgresql·c#·efcore
短剑重铸之日5 小时前
《7天学会Redis》Day2 - 深入Redis数据结构与底层实现
数据结构·数据库·redis·后端
Zoey的笔记本6 小时前
「支持ISO27001的GTD协作平台」数据生命周期管理方案与加密通信协议
java·前端·数据库
什么都不会的Tristan6 小时前
MybatisPlus-扩展功能
数据库·mysql
超级种码6 小时前
Redis:Redis 数据类型
数据库·redis·缓存