sql面试题,求大神解答

菜鸟军爷 学生  2017-11-07 11:32:44
...全文
172 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qq_16680181 2017-11-08
select a.*,b.avg_fenshu FROM chengji a LEFT JOIN (select kemu,AVG(fenshu) as avg_fenshu FROM chengji GROUP BY kemu) b on a.kemu = b.kemu where a.fenshu < b.avg_fenshu select name,GROUP_CONCAT(fenshu) from chengji where fenshu > 80 GROUP BY NAME HAVING count(*) > 1 SELECT a. NAME, substring_index(a.fenshus, ',', 1) AS '数学', substring_index(a.fenshus, ',', - 1) AS '语文' FROM ( SELECT NAME, GROUP_CONCAT(kemu ORDER BY kemu) AS kemus, GROUP_CONCAT(fenshu ORDER BY kemu) AS fenshus FROM chengji GROUP BY NAME ) a SELECT name,kemu,if(fenshu < 80,'合格',if(fenshu >= 90,'优秀','中等')) FROM chengji
  • 打赏
  • 举报
回复
凯歌6 2017-11-08
一: Select a.name,a.kemu,a.fenshu,(Select avg(b.fenshu) From t_grade b where a.kemu=b.kemu GROUP BY b.kemu ) From t_grade a Where a.fenshu<(Select avg(b.fenshu) From t_grade b where a.kemu=b.kemu GROUP BY b.kemu ) GROUP BY a.kemu 二: SELECT name,kemu,fenshu from t_grade where name not in(select name from t_grade where fenshu<=80) 三: SELECT name as 姓名, MAX( CASE WHEN kemu='语文' THEN fenshu END ) AS 语文, MAX( CASE WHEN kemu='数学' THEN fenshu END ) AS 数学 FROM t_grade GROUP BY name 四: select name,kemu, case when fenshu>=90 then '优秀' when fenshu<90 and fenshu>=80 then '中等' when fenshu<80 then '合格' end as fenshu from t_grade
  • 打赏
  • 举报
回复
相关推荐
发帖
Java EE
加入

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2017-11-07 11:32
社区公告
暂无公告