Stuff
public text v1 · immutableSELECT COUNT( DISTINCT fault.faultref ) AS c, users.id, users.name
FROM users, fault
WHERE users.teamid =1
AND (
users.id = fault.ownerid
OR (
SELECT COUNT( DISTINCT fault.faultref
FROM fault
WHERE fault.ownerid = users.id
AND lastclosed IS NULL
AND resolved IS NULL ) =0
)
AND users.id !=1
AND users.holiday IS NULL
AND fault.resolved IS NULL
AND fault.lastclosed IS NULL
GROUP BY users.id
ORDER BY c