12.2总结
作者:互联网
查询所有字段信息
SELECT * FROM student
查询部分字段
SELECT sname,birth,money FROM student
查询时添加常量列
SELECT sname AS s,birth AS b,money AS m FROM student
查询时合并列
查询每个同学的总成绩
SELECT scid,sid,html+css+js AS grade FROM score
SELECT scid,sid,(html+css+js)/3 AS savg FROM score
查询所有同学的js成绩
SELECT SUM(js) FROM score
查询所有同学科目的总成绩
SELECT SUM(js+css+html) FROM score
查询所有同学html的平均分
SELECT AVG(html) FROM score
查询所有同学所有科目的平均成绩
SELECT AVG(html+css+js) FROM score
查询css的最高分和最低分
SELECT MAX(css),MIN(css) FROM score
判空条件
查询姓名不为空的学生
SELECT * FROM student WHERE sname <> '' AND sname IS NOT NULL
查询姓张的同学信息
SELECT * FROM student WHERE sname LIKE '张%'
查询姓名中带四的学生信息
SELECT * FROM student WHERE sname LIKE '%四%'
查询姓名为两个字的学生信息
SELECT * FROM student WHERE sname LIKE '__'
查询学生的总人数
SELECT COUNT(*) FROM student
分页查询 limit 起始行(从0开始),查询几行
第一页 每页显示两条 起始行=(当前页-1)* 每页显示条数
SELECT * FROM student LIMIT 0,2
第二页
SELECT * FROM student LIMIT 2,2
第三页
SELECT * FROM student LIMIT 4,2
查询所有同学信息,并按照零花钱从高到低排序
SELECT * FROM student ORDER BY money DESC
查询所有同学的成绩,并按照js成绩从小到大排序
SELECT * FROM score ORDER BY js ASC
查询所有女同学的信息,并按照零花钱从低到高排序
SELECT * FROM student WHERE ssex='女' ORDER BY money ASC
查询所有同学成绩,按照css从小到大,按照js从大到小
SELECT * FROM score ORDER BY css,js DESC
查询男女的人数
按谁分组就查谁
SELECT ssex,COUNT(*) FROM student GROUP BY ssex
查询每个班级的html总成绩
SELECT class,SUM(html) FROM score GROUP BY class
查询人数大于2的性别
SELECT ssex FROM student GROUP BY ssex HAVING COUNT(*)>2
查询时去除重复记录
查询学生表都有哪些性别
SELECT DISTINCT ssex FROM student
SELECT DISTINCT(ssex) FROM student
查询条件
查询sid为3的同学所有信息
SELECT *FROM student WHERE sid=3
查询性别为男的同学姓名、性别、生日
SELECT sname,ssex,birth FROM student WHERE ssex='男'
查询零花钱大于100的同学的编号、姓名、零花钱
SELECT sid,sname,money FROM student WHERE money>100
查询性别为女,零花钱大于100的同学姓名、零花钱
SELECT sname,money FROM student WHERE ssex='女' AND money>100
查询零花钱大于200或者时男同学的姓名零花钱
SELECT sname,money FROM student WHERE ssex='男' OR money>200
查询html成绩在80--100分之间的同学信息
SELECT * FROM score WHERE html>=80 AND html<=100
等价于
SELECT * FROM score WHERE html BETWEEN 80 AND 100
查询三门课总成绩在200-230之间的同学编号、三门课总成绩
SELECT sid,html+css+js AS grade FROM score WHERE html+css+js BETWEEN 200 AND 230
查询html成绩不是满分的同学信息
SELECT * FROM score WHERE html<>100
标签:总结,score,查询,12.2,html,student,WHERE,SELECT 来源: https://www.cnblogs.com/aning666/p/15639019.html