查询所有学生的信息
SELECT * FROM USER;
查询姓名是李白的学生
SELECT * FROM USER WHERE NAME = ‘李白’ ;
查询1班是上海的学生
SELECT * FROM USER WHERE hometown=‘上海’ AND class = ‘1班’;
查询家乡是北京或是上海的学生
SELECT * FROM USER WHERE hometown=‘北京’ OR hometown=‘上海’;
查询小乔的年龄
SELECT age FROM USER WHERE NAME=‘小乔’;
查询家乡不在北京的学生
SELECT * FROM USER WHERE hometown!= ‘北京’;
查询年龄小于20岁的女同学
SELECT * FROM USER WHERE sex=‘女’ AND age<20;
查询年龄为18至20岁的学生
SELECT * FROM USER WHERE age BETWEEN 18 AND 20;
查询北京学生的年龄总和
SELECT SUM(age) ‘年龄总和’ FROM USER WHERE hometown=‘北京’;
查询女生的平均年龄
SELECT AVG(age) ‘女生平均年龄’ FROM USER WHERE sex=‘女’;
查询姓名包含白的学生
SELECT * FROM USER WHERE NAME LIKE ‘%白%’;
查询所有学生信息,按年龄从大到小排序,年龄相同时,再按学号从大到小排序
SELECT * FROM USER ORDER BY age DESC;
查询女生的最大年龄
SELECT MAX(age) ‘女生最大年龄’ FROM USER WHERE sex=‘女’;
查询北京学生的年龄总和
SELECT SUM(age) ‘北京学生年龄总和’ FROM USER WHERE hometown=‘北京’;
查询各种性别的人数
SELECT sex ‘性别’,COUNT() ‘人数’ FROM USER GROUP BY sex;
查询男生总人数
SELECT COUNT() ‘男生总人数’ FROM USER WHERE sex=‘男’;
mysql
最新推荐文章于 2022-10-28 10:43:36 发布