SQL有没遍历的方法,求一条SQL语句 假设有一张这样的表:表名:student字段:ID(学号), sex(性别), class_id(班级)想求出每个班级中sex = '男'的数目用一个SQL语句,怎么弄?求大侠们指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select class_id,count(1) from studentwhere sex='男'group by class_id select class_id,count(distinct id) as cntfrom studentwhere sex = '男'group by class_id 但你的需求不要遍历,只要select class_id,count(*) from student where sex='男' group by class_id就行了. SELECT CLASS_ID,COUNT(1) AS '数目'FROM STUDENT WHERE SEX = '男'GROUP BY CLASS_ID select class_id,sum(case sex when '男' then 1 else 0 end) as 数目from studentgorup by class_id 游标,identity加循环,都可以吧 不用遍历,直接Group By 就行了 select class_id , count(1) 数目 from student where sex = '男' group by class_id 将查询结果写入新的表 ------求查询------ 服务重启失败 一张表 存储到一定数据他会翻页存储吗,这个一定量是多少? 急!!!动态生成表的存储过程 关于分布式事务,大虾来! 存储过程问题 请高手帮助 急!! 请教关于SQLserver image字段更新的问题~~~解决问题送分 我在Win2000上装SQL Server7.0时,没有注意字符集的选择,其默认的是英文。现在我想把他改为中文不知有何办法? 如何更改SQL Server中的计算型字段 求解:查询一天内重复的数据 SQL数据类型的如何选用,苦恼呀!!!
select class_id,count(1) from student
where sex='男'
group by class_id
select class_id,count(distinct id) as cnt
from student
where sex = '男'
group by class_id
select class_id,count(*) from student where sex='男' group by class_id就行了.
FROM STUDENT
WHERE SEX = '男'
GROUP BY CLASS_ID
class_id,sum(case sex when '男' then 1 else 0 end) as 数目
from
student
gorup by
class_id