--1 select r.读者号, r.读者姓名, b.书名, count(j.书号) as 借阅本数 from 读者表 r inner join 借阅表 j on r.读者号=j.读者号 inner join 图书表 b on b.书号=j.书号 where 出版社='机械工业出版社' group by j.读者号 having count(j.书号)>1 order by count(j.书号) desc--2 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价> ( select max(单价) from 图书表 where 出版社='机械工业出版社' )--3 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价> ( select min(单价) from 图书表 where 出版社='机械工业出版社' )
后两个还可以写成 --2 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价 >all ( select 单价 from 图书表 where 出版社='机械工业出版社' )--3 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价>any ( select 单价 from 图书表 where 出版社='机械工业出版社' )
2.查询‘科学出版社’的图书单价比‘机械工业出版社’最高单价还高的图书书名及单价 select * from 图书表 T where 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社') And 出版社='科学出版社'
1. select b.读者号,b.姓名,a.书名,count(c.书号) from 图书表 a,读者表 b,借阅表 c where a.书号=c.书号 and b.读者号=c.读者号 and a.出版社='机械工业出版社' group by b.读者号,b.姓名 having count(c.书号)>1 order by 3 desc
--2 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社')--3 select 书名, 单价 from 图书表 where 出版社='科学出版社' and 单价>(select min(单价) from 图书表 where 出版社='机械工业出版社')
我发现第1题有点问题,如果1个读者借过两本书,那它的书名将无法都写出来,如果没有书名那列的话,应该写成: --1 select j.读者号, r.姓名, count(j.书号) as 借阅本数 from 读者表 r inner join 借阅表 j on r.读者号=j.读者号 inner join 图书表 b on b.书号=j.书号 where 出版社='机械工业出版社' group by j.读者号, r.姓名 having count(j.书号)>1 order by count(j.书号) desc
服务器: 消息 8120,级别 16,状态 1,行 1 列 'a.书名' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。其实这个书名是无法在这道题中显示出来的,觉得题出错了
--1
select r.读者号, r.读者姓名, b.书名, count(j.书号) as 借阅本数
from 读者表 r
inner join 借阅表 j on r.读者号=j.读者号
inner join 图书表 b on b.书号=j.书号
where 出版社='机械工业出版社'
group by j.读者号
having count(j.书号)>1
order by count(j.书号) desc--2
select 书名, 单价
from 图书表
where 出版社='科学出版社' and 单价>
(
select max(单价)
from 图书表
where 出版社='机械工业出版社'
)--3
select 书名, 单价
from 图书表
where 出版社='科学出版社' and 单价>
(
select min(单价)
from 图书表
where 出版社='机械工业出版社'
)
--2
select 书名, 单价
from 图书表
where 出版社='科学出版社' and 单价 >all
(
select 单价
from 图书表
where 出版社='机械工业出版社'
)--3
select 书名, 单价
from 图书表
where 出版社='科学出版社' and 单价>any
(
select 单价
from 图书表
where 出版社='机械工业出版社'
)
select * from 图书表 T where 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社') And 出版社='科学出版社'
select
b.读者号,b.姓名,a.书名,count(c.书号)
from
图书表 a,读者表 b,借阅表 c
where
a.书号=c.书号 and b.读者号=c.读者号
and
a.出版社='机械工业出版社'
group by
b.读者号,b.姓名
having
count(c.书号)>1
order by
3 desc
select
书名, 单价
from
图书表
where
出版社='科学出版社' and 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社')--3
select
书名, 单价
from
图书表
where
出版社='科学出版社'
and
单价>(select min(单价) from 图书表 where 出版社='机械工业出版社')
--1
select j.读者号, r.姓名, count(j.书号) as 借阅本数
from 读者表 r
inner join 借阅表 j on r.读者号=j.读者号
inner join 图书表 b on b.书号=j.书号
where 出版社='机械工业出版社'
group by j.读者号, r.姓名
having count(j.书号)>1
order by count(j.书号) desc
列 'a.书名' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。其实这个书名是无法在这道题中显示出来的,觉得题出错了