这个问题我学了select语句之后还是不会,请问要怎么弄呀?
这个问题我学了select语句之后还是不会,请问要怎么弄呀?希望大家教教我,感激不尽。GROUP BY(school,age) HAVING COUNT(score)>=70/COUNT(studentnum)
分组+行级过滤 庚午 发表于 2018-9-29 23:01
GROUP BY(school,age) HAVING COUNT(score)>=70/COUNT(studentnum)
分组+行级过滤
您好!题目中说需要找到那个合格率最大的年龄段,可是我看不懂您的代码哪里体现了找最大? {:10_266:}大家都出去玩了吗? sunny霉神 发表于 2018-9-30 14:32
您好!题目中说需要找到那个合格率最大的年龄段,可是我看不懂您的代码哪里体现了找最大?
SELECT 语句自己填充就可以了,多试几遍~就会有收获的 mysql> select a.school,a.age,a.pass from (select school,age,sum(score>=70)/count(*) as pass from students group by school,age) as a
-> inner join (select school,max(pass) as mp from (select school,age,sum(score>=70)/count(*) as pass from students group by school,age) as a group by school) as b
-> on (a.school=b.school and a.pass=b.mp);
我弄出来这个很复杂。。。不知道还有没有简单点的方法。。。 sunny霉神 发表于 2018-10-1 01:18
我弄出来这个很复杂。。。不知道还有没有简单点的方法。。。
我觉得你这个已经很简单了,用连接实现,效率也不错
可以用cte语句简化一下,但实质一下。我用IN表示,实现了一下
我用cte语句表示一下:
with rn1 as(
select school,age,sum(score>=70)/count(1) as
from students
group by school,age
)
select school,age,pass
from rn1
where (school,pass) in (select school,max(pass) from rn1 group by school )
页:
[1]