1
SELECT (res.phone_number_count + res.computer_count) AS user_count FROM (
    SELECT COUNT(DISTINCT phone_number_id) AS phone_number_count, COUNT(DISTINCT computer_id) AS computer_count
    FROM opinions
    WHERE case_id = 1
) AS res;

一意の phone_number_ids と computer_ids の両方の数を取得しようとしています。

4

1 に答える 1

3

どうですか:

SELECT COUNT(DISTINCT phone_number_id) + COUNT(DISTINCT computer_id) AS user_count
FROM opinions
WHERE case_id = 1
于 2013-04-27T17:12:10.880 に答える