1

我的查询是

select COUNT(*) from result 
where test_id in (select test_id 
                    from test_schedule 
                    where scheduler_id in (select user_id 
                                           from users 
                                           where user_type=1))
4

3 回答 3

1

尝试这个:

SELECT COUNT(r.*)
FROM result r
INNER JOIN test_schedule s ON r.test_id = s.test_id
INNER JOIN users u ON s.scheduler_id  = u.user_id
WHERE u.user_type = 1
于 2012-10-30T07:38:24.787 回答
0
SELECT COUNT(r.*)
FROM result r
RIGHT JOIN test_schedule s USING(test_id)
RIGHT JOIN users u ON s.scheduler_id  = u.user_id
WHERE u.user_type = 1
于 2012-10-30T07:44:48.667 回答
0
SELECT COUNT(*)
FROM result r
JOIN (SELECT DISTINCT test_id
      FROM test_schedule s
      JOIN users u ON s.scheduler_id = u.user_id
      WHERE u.user_type = 1) s
USING (test_id)

DISTINCT 是必要的,以防止行与匹配的其他表中的所有行相乘。

于 2012-10-30T07:53:03.123 回答