本文介绍了加入2个表的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Tables:
Book: BID,BNAME,BPRICE,SID
Author: AID,ANAME,BID
Question:
Write query which give list of Books, having more than one Author.
这个问题在采访中被问到了我。
This question was asked to me in interview.
推荐答案
select b.bname, a.aname from book b inner join author a on b.bid = a.bid
获取所有列表作者和书籍。但是,你想要的是拥有多个作者的书籍。所以答案是:
to get a list of all authors and books. However, what you want, is books having more than one author. So the answer is:
select a.aname, count(b.bname) from book b inner join author a on b.bid = a.bid group by a.aname having count(b.bname) > 1
这篇关于加入2个表的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!