我在mySQL中有两个表。 coffee_users和coffee_product_registrations。每个用户可以拥有多个产品注册。我尝试选择产品注册次数超过1的用户,但我收到以下错误:
#1054 - Unknown column 'coffee_users.uid' in 'on clause'
执行此操作时:
SELECT c.uid
FROM
`coffee_users` as c
JOIN (
select uid
from `coffee_users`
group by `uid`
having count(*)>1
) coffee_product_registrations
on coffee_users.uid = coffee_product_registrations.uid
这可行吗?
答案 0 :(得分:1)
也许这就是你想要的?
SELECT c.uid
FROM coffee_users c
JOIN coffee_product_registrations cpr on c.uid = cpr.uid
GROUP BY c.uid
HAVING COUNT(cpr.id) > 1