查询3号读者2020所借图书
2020-12-13 17:20:06 · 浏览次数:0 来源:U租号网
vfp 查询所借图书的总价在150元以上的读者编号,读者名称和所借图书的总价
你的WHERE后面要有GROUP BY 关键字
select a.readerno,b.readername,sum(c.price) from borrow a,reader b,book c;
where c.bookno=a.bookno;
and b.readerno=a.readerno;
group by a.readerno,b.readername;
having sum(c.price)>150;
使用子查询,获取当前没有被读者借阅的书籍的图书信息
语句如下:
select dzh as 读者号,(select dzm from reader where dzh=a.dzh) as 读者名,(select sfz from reader where dzh=a.dzh) as 身份证,(select dh from reader where dzh=a.dzh) as电话,(select dz from reader where dzh=a.dzh) as 地址 from record as a where ghbj='否' and datediff(dd,jyrq,getdate())>=60
其实这题用Inner Join来做更好,用子查询会大大影响查询速度,不过既然题目是这样出的就这么写吧。
SQL查询至少借阅三本图书的读者编号,姓名,图书编号,图书名称,按读者编号排序输出
一张表:借阅表(包含所有信息)
select读者编号,姓名,图书编号,图书 from 借阅表 where 读者编号 in (select 读者编号 from 借阅表 group by 读者编号 having count(读者编号)>=3)
二张表:借阅表 ,个人信息基本表
select t1.读者编号,t1.姓名,t2.读书编号,t2.读书 from 个人信息基本表 t1,借阅表 t2 where t2.读者编号 in (select 读者编号 from 借阅表 group by 读者编号 having count(读者编号)>=3) and t1.读者编号=t2.读者编号