sql求助大神

董哥007 2018-04-06 07:54:12
我先贴出基础表

课程表


成绩表


现在问题是 :按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩

我给出我的sql
SELECT sc1.sid,
(SELECT score from sc sc2 where sc2.Sid=sc1.Sid and sc2.Cid='01') '01',
(SELECT score from sc sc2 where sc2.Sid=sc1.Sid and sc2.Cid='02') '02',
(SELECT score from sc sc2 where sc2.Sid=sc1.Sid and sc2.Cid='03') '03',
sc1.avgs
from
(SELECT sid,avg(score) avgs from sc GROUP BY sid) sc1
ORDER BY sc1.avgs desc


效果图


我想要的是,我想把null 换成 暂无数据来填充 不知道sql怎么写。
...全文
382 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
董哥007 2018-04-08
  • 打赏
  • 举报
回复
好的 我回家试试 公司没数据库
qq_20899941 2018-04-08
  • 打赏
  • 举报
回复
SELECT sc1.sid, if((SELECT score from sc sc2 where sc2.sid=sc1.Sid and sc2.cid='01')is null,'暂无数据',(SELECT score from sc sc2 where sc2.sid=sc1.sid and sc2.cid='01')) '01', if((SELECT score from sc sc2 where sc2.sid=sc1.Sid and sc2.cid='02')is null,'暂无数据',(SELECT score from sc sc2 where sc2.sid=sc1.sid and sc2.cid='02')) '02', if((SELECT score from sc sc2 where sc2.sid=sc1.sid and sc2.cid='03')is null,'暂无数据',(SELECT score from sc sc2 where sc2.sid=sc1.sid and sc2.cid='03')) '03', sc1.avgs from (SELECT sid,avg(score) avgs from sc GROUP BY sid) sc1 ORDER BY sc1.avgs desc
xuzuning 2018-04-07
  • 打赏
  • 举报
回复
董哥007 2018-04-07
  • 打赏
  • 举报
回复

报错了啊
xuzuning 2018-04-07
  • 打赏
  • 举报
回复
ifnull(score,'暂无数据',score)
董哥007 2018-04-07
  • 打赏
  • 举报
回复
说一下具体做法。请指教
xuzuning 2018-04-07
  • 打赏
  • 举报
回复
那就需要改变列类型
董哥007 2018-04-07
  • 打赏
  • 举报
回复
好吧 我自己看看

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧