mysql查询语句
Posted 乔儿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql查询语句相关的知识,希望对你有一定的参考价值。
-- 查询所有学生的姓名和性别(条件运算)
select stuname as 姓名, case stusex when 1 then ‘男‘ else ‘女‘ end as 性别 from tb_student;
select stuname as 姓名, if(stusex, ‘男‘, ‘女‘) as 性别 from tb_student;
-- 查询姓"杨"名字两个字的学生姓名和性别(模糊)
select stuname, stusex from tb_student where stuname like ‘杨_‘;
-- 查询姓"杨"名字三个字的学生姓名和性别(模糊)
select stuname, stusex from tb_student where stuname like ‘杨__‘;
-- 查询没有录入家庭住址的学生姓名(空值) select stuname from tb_student where stuaddr is null;
-- 查询课程编号为1111的课程的平均成绩(筛选和聚合函数)
select avg(score) from tb_record where cid=1111;
-- 查询每个学生的学号和平均成绩(分组和聚合函数)
select sid as 学号, avg(score) as 平均分 from tb_record group by sid;
以上是关于mysql查询语句的主要内容,如果未能解决你的问题,请参考以下文章