SELECT book.code, book.bookname, book.author, book.publisher, ifnull(cc.testtime,0)
------------------------------------------------------------------------------------------------------
SELECT book.code, book.bookname, book.author, book.publisher, if(cc.testtime is null,0,cc.testtime)
------------------------------------------------------------------------------------------------------
SELECT book.code, book.bookname, book.author, book.publisher, if(isnull(cc.testtime),0,cc.testtime)
------------------------------------------------------------------------------------------------------
as borrow_times
FROM book LEFT JOIN (select loan.code as testcode ,count(loan.stuid) as testtime
from loan
group by loan.code) AS cc ON book.code=cc.testcode
ORDER BY book.code;
===============================
Result:
===============================
| code | bookname | author | publisher | borrow_times |
|---|---|---|---|---|
| c001 | Harry | Charlie | charlie | 2 |
| c002 | The Ring | Andy | Tonli | 1 |
| c003 | Konan | Dowa | Tonli | 0 |
No comments:
Post a Comment