复制代码 代码示例:
select a.name,count_neg,count_plus from
(select count(id) as count_plus,name from score2 where score >=60 group by name) a,
(select count(id) as count_neg,name from score2 where score <=60 group by name) b
where a.name=b.name
即必须至少用2个语句。
发现mysql支持if,用if来实现:
复制代码 代码示例:
select name, sum(if(score>=60,1,0)),sum(if(score<60,1,0)) from score2 group by name
单个select语句实现mysql查询统计次数的方法简单吧。
原理就是大于60,就赋值为1,那么sum就是计数了。
mysql查询统计函数中的count
一个题目:统计所有女生成绩大于90以上有总数
开始这样写:
复制代码 代码示例:
s q l = " s e l e c t 女 生 成 绩 f r o m u s e w h
mysql查询单条语句_单条select语句实现
最新推荐文章于 2024-04-25 20:51:25 发布
本文介绍了如何在MySQL中使用单条SELECT语句进行查询统计。通过示例展示了利用IF函数统计分数大于60和小于等于60的记录数,并解释了原理。同时,讨论了使用COUNT函数提高查询效率,特别是在处理大量数据时,避免逐条查询的慢速问题。
摘要由CSDN通过智能技术生成