如果连接表的计数大于10,如何选择记录?

时间:2011-12-03 06:53:12

标签: mysql sql

我需要选择memberid计数logins大于10

SELECT COUNT(DISTINCT(member.member_id)) FROM member LEFT JOIN location_member ON (member.member_id = location_member.member_id) WHERE Month(FROM_UNIXTIME(member.r_date)) = 11 AND Year(FROM_UNIXTIME(member.r_date)) = 2011 AND FROM_UNIXTIME(member.r_date, '%d') = 28 AND member.pc_address_validated <> 1 **OR (if checkins > 10)**

我写了这个查询:

{{1}}

如何检查计数是否超过10?

2 个答案:

答案 0 :(得分:7)

SELECT memberId
FROM checkin
GROUP BY memberId
HAVING COUNT(1) > 3

要解决您的新问题:

SELECT member.member_id
FROM member
INNER JOIN checkins ON member.member_id = checkins.member_id
LEFT JOIN location_member ON (member.member_id = location_member.member_id)
WHERE Month(FROM_UNIXTIME(member.r_date)) = 11
   AND Year(FROM_UNIXTIME(member.r_date)) = 2011
   AND FROM_UNIXTIME(member.r_date, '%d') = 28
   AND member.pc_address_validated <> 1
GROUP BY member.member_id
HAVING COUNT(1) > 10

答案 1 :(得分:0)

您的查询与此类似,

select ck.memberId,ck.login from Member m join
CheckIn ck on m.id = ck.memberId
group by ck.memberId, ck.login having count(ck.login) > 3