科学健康资讯 · 内容仅供参考,不替代专业诊疗 联系我们|疾病百科
操作系统

selectdistinct(select distinct多个字段)

2023-05-02 操作系统 本文链接

数据分析师技能之每天两个sql知识点(二)

1 用DISTINCT关键字去重

例如,学生表student_table中存储了学生姓名student_name,学生班级student_class,学号student_no,性别gender,年龄age等信息,要从学生表中查看一共有哪几个班级,SQL代码如下:

SELECT DISTINCT student_class

FROM student_table;

2 用ORDER BY 语句排序,ASC关键字表示正序排列,DESC关键字表示倒序排列

例如查询学生的姓名和学号,并根据学号从小到大排序

SELECT student_name, student_no

FROM student_table

ORDER BY student_no ASC;(此处ASC关键字可以省略,若要求倒序排列,则不可省略DESC关键字)

from->on->join->where->group by->sum、count、max、avg->having->select->distinct->order by->top//@little小小z先森:执行顺序应该这样吧 from join on where group by 聚合函数 having select distinct order by limit

洛云讲透SQL

SQL执行顺序#sql

50个常用sql语句(36——40)

36、查询任何一门课程成绩在70分以上的姓名、课程名称和分数;

SELECT distinct student.S#,student.Sname,SC.C#,SC.score

FROM student,Sc

WHERE SC.score>=70 AND SC.S#=student.S#;

37、查询不及格的课程,并按课程号从大到小排列

select c# from sc where scor e <60 order by C# ;

38、查询课程编号为003且课程成绩在80分以上的学生的学号和姓名;

select SC.S#,Student.Sname from SC,Student where SC.S#=Student.S# and Score>80 and C#='003';

39、求选了课程的学生人数

select count(*) from sc;

40、查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩

select Student.Sname,score

from Student,SC,Course C,Teacher

where Student.S#=SC.S# and SC.C#=C.C# and C.T#=Teacher.T# and Teacher.Tname='叶平' and SC.score=(select max(score)from SC where C#=C.C# );

本文内容仅供健康科普参考,不能替代专业医疗诊断和治疗建议。如有身体不适,请及时就医并遵从医师指导。

相关阅读