题解 | #某乎问答高质量的回答中用户属于各级别的数量#

某乎问答高质量的回答中用户属于各级别的数量

https://www.nowcoder.com/practice/69c85db3e59245efb7cee51996fe2273

select 
    level_cut,
    count(level_cut)
from (
select
    case 
    when author_level between 1 and 2 then '1-2级'
    when author_level between 3 and 4 then '3-4级'
    when author_level between 5 and 6 then '5-6级' 
    end as level_cut # 将author_level的值进行一个数值判断,并写入文本
from
    author_tb
    join answer_tb using (author_id)
where 
    char_len >= 100
) t1
group by 
    level_cut
order by 
    count(level_cut) desc

本题难度不高,只要针对author_level做一个数值判断填充文本即可,注意else可有可无。如果添加else 必须有默认值。

tips:在这道题中 在条件判断case when中写入的文本只能是 单引号的形式'XX',不可以是反引号``,反引号用于引用数据库对象(如表和列名),而单引号用于表示字符串值

全部评论

相关推荐

牛牛不会牛泪:脉脉太多这种了,纯水军
点赞 评论 收藏
分享
09-22 22:22
中山大学 Java
双尔:赌对了,不用经历秋招的炼狱真的太好了,羡慕了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务