开发者

MYSQL query for counting number of books

  BOOK_COPIES (Book_ISBN [pk,fk], Branch_ID [pk,fk], Num_Copies)
  BOOK_LOANS (Book_ISBN [pk,fk], Branch_ID [pk,fk],Card_Num [pk,fk], Date_Out, Date_Due)
  LIBRARY_BANCH (Branch_ID [pk], Branch_Name, Address)

   Q. For each branch list the branch ID and the number of books they have. This is the     
      total number of books including multiple copies.

solution: select lb.branchid from library branch lb,bookcopies bc where bc.branc开发者_开发技巧hid=b.branchid group by lb.branchid;

However I'm finding it difficult to get the number of books they have?


Try this, it should work:

SELECT Branch_ID, SUM(Num_Copies) totcopies
FROM BOOK_COPIES
GROUP BY Branch_ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜