Mysql
 sql >> Database >  >> RDS >> Mysql

Hai bisogno di assistenza per contare i libri più diversi

Prova questo:

SELECT c.cust_id, COUNT(DISTINCT od.book_id) bookCnt
FROM a_bkorders.customers c 
INNER JOIN a_bkorders.order_headers oh ON c.cust_id = oh.cust_id 
INNER JOIN a_bkorders.order_details od ON oh.order_id = od.order_id 
GROUP BY c.cust_id
ORDER BY bookCnt DESC