# 用count是不会统计为null的数据的SELECT query_name,ROUND(AVG(rating/position),2) quality,ROUND(count(IF(rating<3,rating,null))/count(rating)*100,2) poor_query_percentage
FROM Queries
GROUPBY query_name
1.3 运行截图
2 每个帖子的评论数
2.1.1 基本题目信息
2.1.2 示例输入输出
2.2 示例sql语句
# 先找到帖子,然后找到回帖的部分 然后进行拼接即可# 帖子与回帖均有重复的SELECT s1.sub_id post_id,IFNULL(count(s2.parent_id),0) number_of_comments
FROM(SELECTdistinct sub_id,parent_id
FROM Submissions
WHERE parent_id isnull) s1
LEFTJOIN(SELECTdistinct sub_id,parent_id
FROM Submissions
WHERE parent_id isnotnull) s2
ON s1.sub_id=s2.parent_id
GROUPBY s1.sub_id
ORDERBY post_id asc
2.3 运行截图
3 不同国家的天气类型
3.1 题目内容
3.1.1 基本题目信息
3.1.2 示例输入输出
a 示例输入
b 示例输出
3.2 示例sql语句
SELECT c1.country_name,IF(AVG(c2.weather_state)<=15,'Cold',IF(AVG(c2.weather_state)>=25,'Hot','Warm')) weather_type
FROM Countries c1
INNERJOIN(SELECT country_id,weather_state,dayFROM Weather
WHERE date_format(day,'%Y-%m')='2019-11') c2
ON c1.country_id=c2.country_id
GROUPBY c1.country_id