sql数据库一道试题帮忙做做

sql数据库一道试题帮忙做做,第1张

---1)

创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话

CREATE

TABLE

student

(

[id]

[int]

IDENTITY(1,1)

NOT

NULL,

[student_id]

[nvarchar](50)

NULL,

[studen_name]

[nvarchar](50)

NULL,

[age]

[int]

NULL

,

[sex]

[nvarchar](5)

NULL,

[address]

[nvarchar](200)

NULL,

[tel]

[nvarchar](20)

NULL

)

--2)

修改学生表的结构,添加一列信息,学历

education

alter

table

student

add

education

nvarchar(10)

NULL

--3)

修改学生表的结构,删除一列信息,家庭住址

alter

table

student

drop

column

address

--5)

修改学生表的数据,将电话号码以11开头的学员的学历改为“大专”

update

student

set

education='大专'

where

tel

like

'11%'

--6)

删除学生表的数据,姓名以C开头,性别为‘男’的记录删除

delete

student

where

studen_name

like

'C%'

and

sex='男'

--7)

查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号示出来

select

studen_name,student_id

from

student

where

age<12

and

education='大专'

--8)

查询学生表的数据,查询所有信息,列出前25%的记录

select

TOP

25

PERCENT

*

from

student

--9)

查询出所有学生的姓名,性别,年龄降序排列

select

studen_name,sex,age

from

studen

order

by

age

desc

--10)

按照性别分组查询所有的平均年龄

select

avg(age)

as

age

from

studen

group

by

sex

1. select '类别为:'+tushuleibie 图书分类 from T_Book

2. select shuming 书名,zuozhe 作者,jiage*0.7 价格 from T_Book where chubanshe ='机械工业出版社'

3. select shuming 书名,zuozhe 作者,jiage 价格, chubanshe 出版社 from T_Book where jiage between 30 and 60

4. select top 3 shuming 书名,zuozhe 作者,chubanshe 出版社, jiage 价格 from T_Book order by jiage desc

6.select chubanshe 出版社,AVG(jaige) 平均价,MAX(jiage) 最高价 ,MIN(jaige) 最低价 from T_Book group by chubanshe order by SUM(jiage) desc

10.select top 1 chubanshe 出版社, count(*) 出版图书个数 from T_Book group by chubanshe order by COUNT(*) desc

book表的做好了 reader的自己做吧 字段名我用拼音做代替的 你自己替换成你表中的字段

1

create

table

学生

(学号

char(9)

not

null

primary

key,

姓名

varchar(20)

not

null,

性别

char(2)

check

(性别='男'

or

性别='女'),

年龄

int,

专业

varchar(20))

2

update

课程

set

课程名='SQL数据库'

where

课程号='100003'

3

delete

from

课程

where

课程号='100002'

4

create

table

选课

(

id

int

identify(1,1),

学号

char(9),

课程号

char(6),

分数

int,

foreign

key(学号)

references

学生(学号),

foreign

key(课程号)

references

课程(课程号))

5

insert

into

课程

select

'100001','C语言',2

union

all

select

'100002','数据结构',2

union

all

select

'100003','数据库原理',2

6

create

view

v_选课

as

select

学生.学号,学生.姓名,课程.课程号,课程.课程名,课程.学分,选课.分数

from

学生,课程,选课

where

学生.学号=选课.学号

and

课程.课程号=选课.课程号

7

select

姓名,学号,专业

from

学生

where

姓名

like

'张%'

and

性别='女'

8

select

学号,姓名

from

学生

where

学号

in

(select

学号

from

成绩

where

分数<60)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9895512.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存