SQL Server 基础语法2(超详细!)


选择数据库school

use school--选择数据库school

查询所有学生的学号、姓名和年龄,查询结果列项是中文名

select 
sno 学号,--起别名的三种方法
sname as 姓名,
年龄 = sage
from Student--from是从那个表里找

查询‘计算机’系的所有学生的基本信息

select *--*是通用符号,代表表里的所有数据
from Student
where sdept='计算机'--where条件是这个同学必须是计算机系的

查询所有女同学的姓名及所在的系,显示结果不允许重复出现

select distinct sname,sdept--查询姓名和系--distict 消除重复
from Student --从Student表里
where sex='女'

查询课程号不为‘1’、‘4’、或‘7’的课程的信息

 select *
 from Course
 where cno!=1 and cno!=4 and cno!=7

查询课程号不为‘1’、‘4’、或‘7’的课程的信息

 select *
 from Course
 where cno not in('1','4','7')

查询所有姓‘张’、或‘刘’或‘高’的学生信息

select *
from Student
where sname like '张%' or sname like '高%' or sname like '刘%' 

查询前10条学生信息

select top 10 *
from Student

查询成绩在80-90之间的所有学生成绩记录

select *
from SC
where grade between 80 and 90 

查询成绩在80-90之间的所有学生成绩记录

select *
from SC
where (grade >= 80 and grade <=90) 

猜你喜欢

转载自blog.csdn.net/m0_56981185/article/details/127849688