数据库查询语句例题与答案实验三.pdfVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档