我需要选择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?
答案 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