- é£çµãã¦GROUPã§éè¨
- çµæããã¼ã¹ããããããã«ï¼å¥åãã¤ãã¦ããï¼(æ¤ç´¢çµæã®ãªãã¸ã§ã¯ããé
åã«minã¨ãmaxãããã¨é¢åãªã®ã§)
- min(books.asin) ã¨ã min(books.title) ã¯ãã¶ããããããªãï¼
select books.id, min(books.asin) asin, min(books.title) title, count(*) user_num,
sum(userbooks.peta_cnt) peta_sum, max(userbooks.peta_date) peta_date
from userbooks
left outer join books on books.id = userbooks.bookid
left outer join users on userbooks.userid = users.id
group by userbooks.bookid;
- é£çµãã¦GROUPã§éè¨ã並ã³æ¿ã
select books.id, min(books.asin) asin, min(books.title) title, count(*) user_num,
sum(userbooks.peta_cnt) peta_sum, max(userbooks.peta_date) peta_date
from userbooks
left outer join books on books.id = userbooks.bookid
left outer join users on userbooks.userid = users.id
group by userbooks.bookid
order by peta_date DESC;