1.选择列
use xscj;
select 姓名,专业名,总学分 from xs;
2.定义列别名
select 学号 as number from xs;
当自定义的列标题中含有空格时,必须使用引号将标题引起来。
select 学号 as 'stu number' from xs;
3.替换数据
select 学号,姓名,
case
when 总学分 is null then '尚未选课‘
when 总学分 <50 then '不及格’
when 总学分 >=50 and 总学分 <=52 then '合格'
else '优秀'
end as 等级
from xs
where 专业名='计算机';
4.计算列值
select 学号,课程号
成绩*1.20 as 成绩120
from xs_kc
where 学号=’081101‘;
计算列值使用:+,-,*,?,%
5.消除结果集中得重复行
select distinct|distinctrow 专业名,总学分
from xs;