我有一个带有布尔列的下表,has_object
它指示每一行是否有关联的数字对象。
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| pid | varchar(255) | NO | PRI | | |
| title | text | YES | | NULL | |
| owner_uid | int(11) | YES | | NULL | |
| has_object | int(11) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
我已尝试使用此查询来获取有关每个owner_uid
. 但在我的表中它返回错误的结果:
SELECT
a.owner_uid,
count(b.pid) as count1,
count(c.pid) as count2
FROM
islandora_report a
JOIN islandora_report b ON b.owner_uid = a.owner_uid AND b.has_object = 0
JOIN islandora_report c ON c.owner_uid = a.owner_uid AND c.has_object = 1
GROUP BY a.owner_uid;
结果: