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;
相关推荐
2301_803875614 小时前
PHP 中处理会话数组时的类型错误解析与修复指南
jvm·数据库·python
m0_743623924 小时前
c++如何批量修改文件后缀名_std--filesystem--replace_extension【实战】
jvm·数据库·python
2501_914245935 小时前
CSS如何处理CSS变量作用域冲突_利用特定类名重写变量值
jvm·数据库·python
maqr_1106 小时前
MySQL数据库迁移到云端如何保障安全_数据加密与SSL连接配置
jvm·数据库·python
u0109147606 小时前
MySQL如何限制触发器递归调用的深度_防止触发器死循环方法
jvm·数据库·python
weixin_381288186 小时前
MySQL中如何使用HEX函数转换十六进制_MySQL进制转换函数
jvm·数据库·python
Deitymoon6 小时前
嵌入式数据库——SQLite基础
数据库·sqlite
YMatrix 官方技术社区6 小时前
美国·硅谷|YMatrix 即将亮相 Postgres Conference 2026,前瞻 AI 时代的数据基座
数据库·数据仓库·postgresql·时序数据库·ymatrix
bKYP953cL6 小时前
构建自己的AI编程助手:基于RAG的上下文感知实现方案
数据库·人工智能·ai编程
Bert.Cai6 小时前
MySQL DML简介
数据库·mysql