Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张交易表,记录了购买的人。我想要进行多于一笔交易的人数。我陷入困境的部分是我如何指定Member必须至少匹配两次(例如两个或多个事务)?
Member
我想它会是类似的东西
SELECT COUNT(*) FROM `table` WHERE COUNT(`Member`)>2
但我意识到这不是第二次计数的正确用法。
进一步澄清:我希望结果是包含此条件匹配的用户数量的单行。所以我不希望它返回每个用户匹配多少次或类似的东西。
您需要使用GROUP BY和HAVING。
GROUP BY
HAVING
SELECT COUNT(*) totalMember FROM ( SELECT Member FROM `table` GROUP BY Member HAVING COUNT(Member) > 2 ) a