我有一个不那么简单(也许简单)的MySQL查询问题。
我正试图得到这样的结果:
[用户] [disabled_users] [venue_name]
所以结果会如此:
5,2,AABB
2,0,ABCC
我得到的结果是:
5,2,AABB
2,2,ABCC< - 问题是它找到了2个结果,无论
这是我当前的查询:
SELECT
count(t.uid) as users, /* GET COUNT OF ACTIVE USERS GROUPED BY VENUE ID*/
t3.vid as venue_id /* SOLUTION */
(
SELECT sum(t1.uid) as users /* GET COUNT OF DISABLED USERS GROUPED BY VENUE ID */
FROM t1
JOIN t2 ON (t1.sid = t2.id)
JOIN t3 ON (t2.cid = t3.id)
WHERE t1.tid = 3 AND t3.vid = venue_id /* SOLUTION */
GROUP BY t3.vid
) as disabledUsers
FROM t1
JOIN t2 ON (t1.sid = t2.id)
JOIN t3 ON (t2.cid = t3.id)
WHERE t1.tid = 2
GROUP BY t3.vid;
编辑:解决方案标有/ * SOLUTION * /我添加了两行,一行选择了场地ID(vid),为它提供了一个别名为venue_id,并在我的内部选择中添加了一个额外的条件。