这个问题的SQL语句怎么写?
一下一张表:student_score
name english math chinese
lee 90 87 88
susan 98 83 90
lee 78 88 78
judy 77 96 90
john 88 86 83
susan 87 97 92
judy 77 97 89
john 87 89 85
要求输出这样的一张表:
name max_english max_math max_chinese
lee 90 87 88
susan 98 97 92
……
不知道有没有表达清楚,就是把每个人的各科最高分输出。请问sql语句怎么写?谢谢。
------解决方案--------------------select name,
max_english =max(english),
max_math=max(math),
max_chinese=max(chinese)
from student_score
group by name
------解决方案--------------------select name,max(english) as max_english ,max(math) as max_math, max(chinese) as max_chinese
from student_score
group by name
------解决方案--------------------select name,max(english) "max_english " ,max(math) "max_math ",
max(chinese) "max_chinese "from student_score
group by name
------解决方案--------------------select name,
max_english =max(english),
max_math=max(math),
max_chinese=max(chinese)
from student_score
group by name
----------------------
确实是正解!
你应该把 group by 的含义给搞明白!
分过组之后才取其最大值