急急急 !!!谢谢大家啊。。。SQL 语句查询。。。谢谢了。。

xtianshi00 2012-05-02 03:39:15
books (图书编号,书名,作者,出版社,定价)
book_id. book_name, book_aut, book_pre, price
readers (读者编号,读者姓名,读者性别,办公电话,部门)
reader_id, reader_name, reader_sex, reader_phone, dept
borrowinf (读者编号,图书编号,借期,应还日期,还期)
reader_id, book_id, jcdate, yhdate, ghdate


SQL 查询 一下:


3. 基于图书馆数据库的3个表,用T-SQL语言完成一下操作:
1) 查询全体图书的图书号、书名、作者、出版社和单价
2) 显示所有借阅者的读者号,并去掉重复行
3) 查询全体图书的信息,其中单价打8折,并设置该列的别名为‘打折价’
4) 查询所有单价在20—30元之间的图书信息
5) 查询机械工业出版社、科学出版社、人民邮电出版社的图书信息
6) 查询既不是机械工业出版社、也不是科学出版社出版的图书信息
7) 查询姓名的第二个字符是’建’,并且只有2个字的读者的读者号及姓名
8) 查询姓名不是以‘王’、‘张’或‘李’开头的所有读者的读者号及姓名
9) 查询无归还日期的借阅信息
10) 查询没有按照要求及时归还图书的读者号
11) 查询机械工业出版社图书的平均价格、最高价、最低价
12)查询读者的基本信息及借阅情况


请大家用 SQL 语句查询下。。谢谢啊。。。麻烦;了。。 谢谢啊。。高分送。。。


...全文
806 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
legowren 2012-05-02
  • 打赏
  • 举报
回复
这些技术你都忘记了吗 ?
lsqkeke 2012-05-02
  • 打赏
  • 举报
回复
忘记完了 不懂
--小F-- 2012-05-02
  • 打赏
  • 举报
回复
CHECK约束 自己去查一下。
xupeihuagudulei 2012-05-02
  • 打赏
  • 举报
回复
还真有人做啊。
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
就是 那个 单价不能小于 0 元

性别 要用约束 男女中选择

还有 引用主键 日期大于借出日期的 约束。。。。他们的 表达式 是怎样的
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

SQL code

1、select book_id. book_name, book_aut, book_pre from books
2、select distinct reader_id from borrowinf
3、select *,price*0.8 as '打折价' from books
4、select * from books where price between ……
[/Quote]


books表结构
列名 说明 数据类型 约束说明

单价 出版社确定的图书的单价 浮点型,Float 不能小于0元

readers表结构
列名 说明 数据类型 约束说明

性别 读者性别 字符串,长度为2 从男和女中选择


borrowinf表结构
列名 说明 数据类型 约束说明
读者号 读者的唯一编号 字符串,长度为10 外键,引用读者表的主键
书号 图书的唯一编号 字符串,长度为20 外键,引用图书表的主键
借出日期 借出图书的日期 日期型 非空值
应还日期 应该归还图书的日期 日期型 日期时间应该大于借出日期

这是这三个表的要求。。能不能 用SQL 语句实现下??

各位大大。。。看到 帮下啊。。。。
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
回去 再给你们分啊。。。。顺便 好好学习 SQL 不然 对不起 这么多 大大。。。
yushen945 2012-05-02
  • 打赏
  • 举报
回复
在7楼的基础上简化下
1、select * from books
2、select distinct reader_id from borrowinf
3、select *,price*0.8 as '打折价' from books
4、select * from books where price between 20 and 30
5、select * from books where book_pre in (N'机械工业出版社',N'科学出版社',N'人民邮电出版社')
6、select * from books where book_pre not in(N'机械工业出版社',N'科学出版社出版社')
7、select reader_id,reader_name from readers where reader_name like '_建'
8、select reader_id,reader_name from readers where '[!王张李]%'
9、select * from borrowinf where yhdate is null or len(yhdate)=0
10、select reader_id from borrowinf where ghdate> yhdate
11、select avg(price)as '平均价格',max(price) as '最高价格',min(price) as '最低价格' from books where book_pre =N'机械工业出版社'
12、select * from readers r inner join borrowinf b on r.reader_id=b.reader_id
inner join books bk on b.book_id=bk.book_id

  • 打赏
  • 举报
回复


7) 查询姓名的第二个字符是’建’,并且只有2个字的读者的读者号及姓名
select reader_id, reader_name from readers
where CHARINDEX('建',reader_name)=2 and LEN(reader_name)=2
8) 查询姓名不是以‘王’、‘张’或‘李’开头的所有读者的读者号及姓名
select reader_id, reader_name from readers
where left(reader_name,1) not in('王','张','或','李')
9) 查询无归还日期的借阅信息
select * from borrowinf where ghdate is null
10) 查询没有按照要求及时归还图书的读者号
select * from borrowinf where yhdate<ghdate


最后两题不写了,应该够你及格了

--说明:要不是你是考试,存在挂科的风险,这个我是不会给你写的
--小F-- 2012-05-02
  • 打赏
  • 举报
回复
4) 查询所有单价在20—30元之间的图书信息
select * from books where price between 20 and 30
5) 查询机械工业出版社、科学出版社、人民邮电出版社的图书信息
select * from books where book_pre in('机械工业出版社','科学出版社','人民邮电出版社')
迪迦凹凸曼 2012-05-02
  • 打赏
  • 举报
回复

1、select book_id. book_name, book_aut, book_pre from books
2、select distinct reader_id from borrowinf
3、select *,price*0.8 as '打折价' from books
4、select * from books where price between 20 and 30
5、select * from books where book_pre in (N'机械工业出版社',N'科学出版社',N'人民邮电出版社')
6、select * from books where book_pre not in(N'机械工业出版社',N'科学出版社出版社')
7、select reader_id,reader_name from readers where reader_name like '_建'
8、select reader_id,reader_name from readers where '[!王张李]%'
9、select * from borrowinf where yhdate is null or len(yhdate)=0
10、select reader_id from borrowinf where ghdate> yhdate
11、select avg(price)as '平均价格',max(price) as '最高价格',min(price) as '最低价格' from books where book_pre =N'机械工业出版社'
12、select * from readers r inner join borrowinf b on r.reader_id=b.reader_id
inner join books bk on b.book_id=bk.book_id

  • 打赏
  • 举报
回复


4) 查询所有单价在20—30元之间的图书信息
select * from books where price between 20 and 30
5) 查询机械工业出版社、科学出版社、人民邮电出版社的图书信息
select * from books where book_pre in('机械工业出版社','科学出版社','人民邮电出版社')
6) 查询既不是机械工业出版社、也不是科学出版社出版的图书信息
select * from books where book_pre not in('机械工业出版社','科学出版社')
  • 打赏
  • 举报
回复

3. 基于图书馆数据库的3个表,用T-SQL语言完成一下操作:
1) 查询全体图书的图书号、书名、作者、出版社和单价
select * from books
2) 显示所有借阅者的读者号,并去掉重复行
select distinct 读者编号 from borrowinf
3) 查询全体图书的信息,其中单价打8折,并设置该列的别名为‘打折价’
select book_id. book_name, book_aut, book_pre, 0.8*price as 打折价
from books
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
大家帮下忙。。。这课老师很 2 自己都不会。。我翻过她的邮箱 题目 都是 别人出的。。
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

LZ 这作业,还是最好自己做,虽然开始痛苦些,后面就会有收获。。。。
[/Quote]


这是个正在 考试的 。。。 帮下忙。。。。谢谢
xtianshi00 2012-05-02
  • 打赏
  • 举报
回复
这是 3个表 ~~~~~》。。。。。。。。。。。。

books (图书编号,书名,作者,出版社,定价)
book_id. book_name, book_aut, book_pre, price
readers (读者编号,读者姓名,读者性别,办公电话,部门)
reader_id, reader_name, reader_sex, reader_phone, dept
borrowinf (读者编号,图书编号,借期,应还日期,还期)
reader_id, book_id, jcdate, yhdate, ghdate
Mr_Nice 2012-05-02
  • 打赏
  • 举报
回复
LZ 这作业,还是最好自己做,虽然开始痛苦些,后面就会有收获。。。。

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧