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 に答える