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;
相关推荐
DBA小马哥2 小时前
时序数据库迁移替换与时序数据库分片
数据库·时序数据库
DBA小马哥2 小时前
时序数据库迁移方案在物联网设备监测中的实践与性能突破
数据库·物联网·时序数据库
ID_180079054732 小时前
小红书笔记详情API接口基础解析:数据结构与调用方式
数据结构·数据库·笔记
ruleslol8 小时前
MySQL的段、区、页、行 详解
数据库·mysql
天若有情6738 小时前
校园二手交易系统实战开发全记录(vue+SpringBoot+MySQL)
vue.js·spring boot·mysql
while(1){yan}8 小时前
MyBatis Generator
数据库·spring boot·java-ee·mybatis
それども8 小时前
MySQL affectedRows 计算逻辑
数据库·mysql
是小章啊8 小时前
MySQL 之SQL 执行规则及索引详解
数据库·sql·mysql
富士康质检员张全蛋9 小时前
JDBC 连接池
数据库
yangminlei9 小时前
集成Camunda到Spring Boot项目
数据库·oracle