我有这个加入:表mmp_user 151个用户 表MMP_MMPUBLISH_LOG 网址访问
select user.name as 'Usuário',count(log.referer) as 'Número de Acessos'
from mmp_user user
left JOIN MMP_MMPUBLISH_LOG log on (user.id=log.user_id)
where log.event_date between '2015-08-01' and '2015-08-08'
group by user.id
order by count(log.referer) desc
预期结果: 151行 获得的结果: 11行
请帮帮我
答案 0 :(得分:1)
试试这个
SELECT u.name as 'Usuário',count(log.referer) as 'Número de Acessos'
FROM mmp_user u
LEFT JOIN (
SELECT user_id, referer
FROM MMP_MMPUBLISH_LOG
WHERE event_date BETWEEN '2015-08-01' AND '2015-08-08'
) log ON u.id=log.user_id
group by u.id
order by count(log.referer) desc
PS。下次没有使用“用户”时,它不清楚