- 35
- 0
- 约6.78千字
- 约 8页
- 2021-02-08 发布于天津
- 举报
.
实验三 数据查询语言
一、基本查询
使用相应 SQL语句,完成如下操作:
(1)查询所有用户的用户 ID 和。
select uid , name
from [user]
(2 )查询注年龄最小 3 位用户的用户 ID, 和年龄。
select top 3 ( uid ), name, datediff ( yyyy , birthday , getdate ()) age
from [user]
order by birthday desc
(3)查询库存小于 50 本的所有书目信息。
select *
from book
where stock 50
(4 )查询清华大学的所有书目信息。
select *
from book
where press = 清华大学
(5)查询价格在 50-100 元的所有的书名。
select title
from book
where price 50 and price 100
(6)查询姓“”或“王”或“”且单名的学生的情况。
select *
from [user]
where name like % or name like % or name like 王 % and len ( name)= 2
(7)查询所有书目的书名、及价格,要求升序排列,相同时,按价格从高到底进行排
序。
.
.
select title , press , price
from book
order by press , price desc
(8)查询所有有交易记录的用户 ID 。
select oid
from [order]
where state = 4
二、数据汇总
使用相应 SQL语句,完成如下操作:
(1)查询理工类书目的最高价格、最低价格及平均价格。
select max( price ) max_price , min ( price ) min_price , avg ( price ) avg_price
from book
where category = 1
(2 )查询所有理工类书目的库存总量。
select sum( stock )
from book
where category = 1
(3)查询‘ 1001’号图书被订购的总次数。
select sum( quantity )
from orderbook
where bookid = 1001
(4 )查询不同状态订单的数量。
select state , count ( state )
from [order]
group by state
(5)查询各类别数据的库存总量。
select sum( stock )
from book
.
.
group by category
(6)查询被订购 2 次以上(含 2 次)的图书编号、订购次数,并按照订购次数从高到
低进行排序。
select bookid , sum( quantity )
from orderbook
group by bookid
having count (*)= 2
order by sum( quantity ) desc
三、连接查询
使用相应 SQL语句,完成如下操作:
(1)列出全部用户的用户 ID 、和状态。
select uid , name, userstate
from [user] , userstate
您可能关注的文档
最近下载
- 云南省2024年中考地理试卷附解析答案.pdf VIP
- 青年拔尖人才支持计划自然科学类申报书-广东石油化工学院.pdf VIP
- 医学影像学第一节食管与胃肠道影像学.pptx VIP
- 电力安全操作规程培训课件.pptx VIP
- 一锅法铜催化合成苯并硒唑类衍生.doc VIP
- 病人突发心脏骤停的应急预案演练脚本(2篇).docx
- OECD -二十国集团 经合组织公司治理原则2023.docx
- 2026年树立和践行正确政绩观专题研讨个人发言材料+“一把手”在树立和践行正确政绩观学习教育读书班开班式上的讲话.docx VIP
- 2023年江西新余中考历史真题及答案.doc VIP
- 2025年江西新能源科技职业学院单招职业技能测试题库及完整答案1套.docx VIP
原创力文档

文档评论(0)