有没有更好的方法来编写这个特定的查询?

时间:2013-04-27 17:08:54

标签: mysql sql

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。

1 个答案:

答案 0 :(得分:3)

怎么样:

SELECT COUNT(DISTINCT phone_number_id) + COUNT(DISTINCT computer_id) AS user_count
FROM opinions
WHERE case_id = 1