1--查询全体学生的学号与姓名
use student
go
select sno,sname
from student
go
2--查询全体学生的记录
use student
go
select *
from student
go
3--查询全体学生的姓名及其年龄
use student
go
select sname 姓名,year(getdate())-year(sbirthday) 年龄
from student
go
4--查询全体男学生的姓名和年龄,并在年龄列前加入一个列,此列的每行数据均为‘age is’常量值。
use student
go
select sname 姓名,insert(age is),year(getdate())-year(sbirthday)年龄
from student
where ssex='男'
go
5--查询07030112班的全体学生的姓名
use student
go
select *
from student
where classno='07030112'
go
6--查询所有年龄在20岁以下的学生的姓名及出生日期。
use student
go
select sname 姓名,sbirthday 出生日期
from student
where sbirthday>'1991-1-1'
7--查询考试成绩有不及格的学生的学号
use student
go
select *
from choice
where grade<60
8--查询年龄在20~23岁之间的学生的姓名、所在班和年龄
use student
go
select sname 姓名,classno 班,year(getdate())-year(sbirthday)年龄
from student
where sbirthday between'1988-1-1'and'1991-1-1'
9--查询07040112、07050111和07030111三个班的学生的姓名和性别
use student
go
select sname,ssex
from student
where classno in('07040112','07030111',' 07050111')
go10--查询既不是1986年出生的学生的姓名和性别。
use student
go
select *
from teacher
where not tbirthday between'1986-1-1'and'1986-12-31'
11--查询姓‘张’的学生的详细信息。
use student
go
select *
from student
where sname like'张%'
12--查询学生表中姓‘张’、姓‘李’和姓‘刘’的学生的情况。
use student
go
select *
from student
where sname like'[张,刘,李]%'
13--查询名字中第2个字为‘小’或‘大’字的学生的姓名和学号。
use student
go
select *
from student
简单查询 统计查询 来自淘豆网m.daumloan.com转载请标明出处.