DISTINCT 를 이용한 COUNT
SELECT u.user_id, u.user_name COUNT(DISTINCT l.logined) AS login_cnt, COUNT(DISTINCT i.items) AS item_cnt FROM user AS u LEFT JOIN logged AS l ON u.user_id=l.user_id LEFT JOIN items AS i ON u.user_id=i.user_id GROUP BY u.user_id
반응형
'db > mysql' 카테고리의 다른 글
mysql get remote ip address (0) | 2015.12.22 |
---|---|
특정사용자 table 권한 주기 (0) | 2015.11.24 |
MySQL db selection Error - ERROR 1184 (08S01) (0) | 2015.05.25 |
MySQL ORDER BY (0) | 2014.07.04 |
mysql root 비번 분실 (0) | 2013.09.24 |