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;
相关推荐
是吕先森21 小时前
mysql基础
数据库·mysql·oracle
Zzz 小生1 天前
LangChain Tools:工具使用完全指南
jvm·数据库·oracle
SQL必知必会1 天前
SQL 计算百分位数和中位数
数据库·sql
亓才孓1 天前
[SpringBoot]UnableToConnectException : Public Key Retrieval is not allowed
java·数据库·spring boot
好学且牛逼的马1 天前
从“混沌初开”到“有序统一”:Java集合框架发展历程与核心知识点详解
前端·数据库·python
REDcker1 天前
HDR Vivid 技术介绍
数据库·算法·视频·sdr·屏幕·显示技术·dhr
冰暮流星1 天前
sql语句之union语句
数据库·sql
2401_876381921 天前
程序人生-Hello’s P2P
数据库·程序人生·p2p
VX:Fegn08951 天前
计算机毕业设计|基于springboot + vue养老院管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
湘-枫叶情缘1 天前
从数据库写作到情绪工程:网络文学工程化转向的理论综述
数据库·人工智能