SQL SERVER实验-- 数据检索

本文是一篇关于SQL SERVER的数据检索实验报告,涵盖了T-SQL语言的使用和数据查询语句的实践,包括多表查询、聚合函数、子查询、存在性查询等操作,旨在提升对数据库查询的熟练度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验3  数据检索

一、实验目的

1)理解T-SQL语言的使用。

2)熟练掌握数据查询语句。

SELECT [ALL|DISTINCT] {*|<表达式>,…,<表达式>}

FROM <表名>[, <表名>…]

[WHERE <条件>]

[GROUP BY <列名>[, <列名>…][HAVING <谓词>]]

[ORDER BY <列名> [ASC|DESC] [, <列名> ASC|DESC]…]

[COMPUTE …]

 

二、实验内容

1 [3.2]b  USE CAP
select aid from AGENTS where [percent]=(select max([percent] )from AGENTS
[3.5]
 Select cid,aid from customers c, agents a  Where cid not in (select cid from orders x
Where x.cid = c.cid and x.aid = a.aid)  And
aid not in (select aid from orders v  Where v.aid = a.aid and v.cid = c.cid)
[3.8]a
   select cid,max(dollars) as MAXSPEND from orders group by cid
[3.8]b   select avg(MAXSPEND) average,cid from  (select cid,max(dollars) as MAXSPEND from orders group by cid)as S group by cid
[3.11]b 
Select avg(temp.maxspend)avgspend,temp.cid
from (select cid,max(dollars) as maxspend from orders  
Group by cid) as temp group by temp.cid
[3.11]f  select pid from products p
where not exists(select cid from customers c where city='Duluth'
and not exists (select * from orders o where o.cid=c.cid and o.pid=p.pid))
[3.11]j  update products
set price=price*1.1 where city='Duluth' or city='Dallas'
[3.11]l  select aid,[percent] from agents a where not exists(select * from customers c
where city='Duluth' and not exists
(select * from orders o where o.cid=c.cid  and o.aid=a.aid)) order by [percent]DESC

<选做>[3.15][3.16][3.17]

 

2、在“学生管理数据库”中建立四张表,分别如下:

学生表:(主键:学号)

学号

姓名

性别

年龄

所在院系

班级

入学日期

20009001

葛文卿

22

国际贸易

国贸2

2000829

20014019

郑秀丽

21

会计学

会计1

200192

20023001

刘成铠

18

计算机

软件2

2002827

20026002

李涛

19

电子学

电子1

2002827

20023002

沈香娜

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值