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.
我正在使用 mysql 5.1
这是我的请求,我想统计年龄在 0 到 14 岁之间且拥有启用帐户的用户数量。
SELECT COUNT( DISTINCT user.id ) AS user FROM profile, user WHERE ( profile.age BETWEEN 0 AND 14 ) AND user.enabled =1
user.enabled=1条件有效,但不是profile.age BETWEEN 0 AND 14
user.enabled=1
profile.age BETWEEN 0 AND 14
您没有将 2 个表连接在一起,因此您只是在运行两者的笛卡尔积。您需要通过一个公共密钥加入它们。
像这样的东西:
SELECT COUNT( DISTINCT user.id ) AS user FROM profile join user on user.id=profile.user_id WHERE ( profile.age BETWEEN 0 AND 14 ) AND user.enabled =1