我有几个连接的查询。我的查询根据他们的总步数返回排行榜的前十名。我想排除在列中具有值的所有行privacy
设置为out
.
MySQL 查询的现状:
SELECT ga.owner_id, u.displayname, g.title, SUM(ga.steps) as `Total Steps`, u.user_id, g.group_id, pri.privacy FROM engine4_passport_goalactivitys ga
LEFT JOIN engine4_passport_goals goals ON goals.goal_id = ga.owner_id
LEFT JOIN engine4_passport_passports p ON p.passport_id = goals.owner_id
LEFT JOIN engine4_users u ON u.user_id = p.owner_id
LEFT JOIN engine4_passport_teams t ON t.owner_id = u.user_id
LEFT JOIN engine4_group_groups g ON g.group_id = t.group_id
LEFT JOIN engine4_passport_privacy pri on pri.user_id = u.user_id
GROUP BY u.user_id
ORDER BY `Total Steps` DESC
LIMIT 0,10
我努力了:
SELECT ga.owner_id, u.displayname, g.title, SUM(ga.steps) as `Total Steps`, u.user_id, g.group_id, pri.privacy FROM engine4_passport_goalactivitys ga
LEFT JOIN engine4_passport_goals goals ON goals.goal_id = ga.owner_id
LEFT JOIN engine4_passport_passports p ON p.passport_id = goals.owner_id
LEFT JOIN engine4_users u ON u.user_id = p.owner_id
LEFT JOIN engine4_passport_teams t ON t.owner_id = u.user_id
LEFT JOIN engine4_group_groups g ON g.group_id = t.group_id
LEFT JOIN engine4_passport_privacy pri on pri.user_id = u.user_id
AND pri.privacy <> 'out'
GROUP BY u.user_id
ORDER BY `Total Steps` DESC
LIMIT 0,10
上面两个查询之间的区别在于:
AND pri.privacy <> 'out'
但是,它不会排除隐私设置为“out”的用户,而是将它们包含在查询中,并将其隐私值设置为null
我也尝试过where
,and
但它只返回 0 行。