MYSQL 查询语句经典例子

MYSQL 查询语句经典例子mysql 经典查询语句例子 assignment3 1 查看前 10 条信息 select from studinfo limit 0 10 2 在学生信息表 StudInfo 中 写出查询学生成绩最高的前 100 条记录的 SQL 语句 select StudName as 姓名

大家好,我是讯享网,很高兴认识大家。

mysql经典查询语句例子:


讯享网

-- assignment3 -- 1、查看前10条信息 select * from studinfo limit 0,10 -- 2、在学生信息表(StudInfo)中,写出查询学生成绩最高的前100条记录的SQL语句 select StudName as '姓名',CourseName as '课程名称',StudScore as '课程成绩' from studinfo as st,courseinfo as cs,studscoreinfo as sc where (st.StudNo=sc.StudNo and cs.CourseID=sc.CourseID) ORDER BY StudScore desc limit 0,100 -- 3、查询所有学生姓名不重名(即无重复姓名)的 SQL 语句 select StudName from studinfo group by StudName HAVING count(*)=1 -- select studname from studinfo group by StudName HAVING count(*)>1 -- select * from studinfo -- select * from studinfo where StudName='陈涛' -- 4. 在学生信息表(StudInfo)中,选出 StudNo(学号),StudName(姓名),StudSex -- (性别),ClassID(班级编号)以中文名字作为别名,将表结构和数据同时存入新表名 -- 为 ChineseStudInfo 的表中 create table ChineseStudInfo SELECT StudNo as '学号',StudName as '姓名',StudGender as '性别',ClassID as '班级编号' from studinfo -- 5. 在学生成绩表(StudScoreInfo)中,查询学号为  的学生成绩 select * from studscoreinfo where StudNo='' -- 6. 写出在学生成绩信息表(StudScoreInfo)中查询学号为 ’’ 并且课程 -- 成绩大于 80 的学生成绩记录的 SQL 语句。 select * from StudScoreInfo where StudNo='' and StudScore>80 -- 7. 写出在学生成绩信息表(StudScoreInfo)中查询成绩在[80,90]之间的所有学 -- 生成绩记录的 SQL 语句(利用 BETWEEN...And 或>=、<=两种方法实现)。 select * from StudScoreInfo where StudScore BETWEEN 80 and 90 select * from StudScoreInfo where StudScore>=80 and StudScore<=90 -- 8. 写出在学生成绩信息表(StudScoreInfo)中查询成绩不在[80,90]之间的所有 -- 学生成绩记录的 SQL 语句(利用 NOT 或 OR 两种方法实现)。 select * from StudScoreInfo where StudScore not BETWEEN 80 and 90 select * from StudScoreInfo where StudScore<80 or StudScore>90 -- 9. 写出在学生成绩信息表(StudScoreInfo)中查询成绩在[60,70]和[80,90] -- 之间的所有学生成绩记录的 SQL 语句(利用 BETWEEN...And 或>=、<=两种方法实现)。 select * from StudScoreInfo where (StudScore BETWEEN 60 and 70) or (StudScore BETWEEN 80 and 90) select * from StudScoreInfo where (StudScore>=60 and StudScore<=70) or (StudScore>=80 and StudScore<=90) -- 10. 写出在课程信息表(CourseInfo)中查询以“计算机”开头的课程信息的 SQL -- 语句。 select * from courseinfo where CourseName like '计算机%' -- 11. 写出在学生信息表(StudInfo)中查询姓名中含有丽字的所有学生信息的 SQL 语 -- 句。 select * from studinfo where studname like '%丽%' -- 12. 写出在学生信息表(StudInfo)中查询姓名为三个字,且以丽字结尾的学生成绩 -- 信息的 SQL 语句 select st.StudName as "姓名",sc.StudNo as '学号',cs.CourseName as "课程名称", sc.StudScore as '成绩' from studinfo as st, studscoreinfo as sc,courseinfo as cs where st.StudNo=sc.StudNo and cs.CourseID=sc.CourseID and sc.StudNo in (select StudNo from studinfo where LENGTH(StudName)=9 and StudName LIKE '%丽') -- desc studinfo

讯享网

小讯
上一篇 2025-04-01 23:52
下一篇 2025-01-19 23:30

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/133916.html