说:
*我那天去面试面试官问100个人,年龄10岁到100岁不定,一条SQL语句弄出10-20岁的平均年龄,20-30的平均年龄,30-4- 40-50....,我当时没想出来
锅巴GG 说:
*select avg(age) ,test from (select *, case when age>=100 then 10 when age>=90 then 9 when age >=80 then 8 when age >=70 then 7 when age>=60 then 6 when age>=50 then 5 when age>=40 then 4 when age>=30 then 3 when age>=20 then 2 when age>=10 then 1 end test from age) a group by test;
*test 变成范围, group一下就行了
阅读(1644) | 评论(0) | 转发(0) |