含视图的SQL语句求解析
$sql=mysqli_query($conn,"select*from(selectbookid,count(bookid)asdegreefromtb_borrowg...
$sql=mysqli_query($conn,"select * from (select bookid,count(bookid)as degreefrom tb_borrow group by bookid) as borr join (select b.*,c.name as bookcasename,p.pubname,t.typenamefrom bookinfo b left join tb_bookcase c on b.bookcase=c.id join tb_publishing pon b.ISBN=p.ISBN join tb_booktype t on b.typeid=t.id where b.del=0) as book onborr.bookid=book.id order by borr.degree desc limit 10")
这一段查询语句怎么理解啊?
谢谢。跪求大神们指导~ 展开
这一段查询语句怎么理解啊?
谢谢。跪求大神们指导~ 展开
展开全部
/*帮你把语句排了下序,层次显得明显一点,也简单的注释下(主要是也不清楚你每张表以及字段各代表什么意思),不懂的追问*/
select *
from (select bookid, count(bookid) as degree
from tb_borrow
group by bookid) as borr --统计tb_borrow表中bookid各有多少条
join (select b.*,c.name as bookcasename,p.pubname,t.typename
from bookinfo b --基础表bookinfo
left join tb_bookcase c on b.bookcase = c.id --左链接tb_bookcase
join tb_publishing p on b.ISBN = p.ISBN --内链接tb_publishing
join tb_booktype t on b.typeid = t.id --内链接tb_booktype
where b.del = 0) as book
on borr.bookid = book.id --外层内链接两张中间表
order by borr.degree desc limit 10 --按照borr表中degree从大到小排序,取前面10条
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询