1
我有一個選擇,可以調出標題,bookcopiesid和名稱。計數和子選擇
select
books.title, borrow.bookcopiesid, users.name, usersid,library_locations.name, checkout_date, return_date, due_date
FROM
books, borrow,users, library_locations, userlib
WHERE
library_locations.id = userlib.libid
AND
userlib.userid = users.id
AND
borrow.bookcopiesid = books.bookid
AND
borrow.usersid = users.id and return_date is not null ;
我怎麼會得到這樣的
SELECT title, COUNT(*) as count
FROM (
SELECT books.title, borrow.bookcopiesid, users.name, usersid,library_locations.name, checkout_date, return_date, due_date
FROM books, borrow,users, library_locations, userlib
WHERE library_locations.id = userlib.libid and userlib.userid = users.id and borrow.bookcopiesid = books.bookid and borrow.usersid = users.id and return_date is not null)
GROUP BY title
ORDER BY count DESC);
工作。
我想顯示的圖書數量爲每名
如果你發佈了你的表結構和你試圖獲得的輸出樣本,這將有所幫助。 – bobwienholt