从结果中删除空值

时间:2017-08-10 07:42:23

标签: mysql

我有这个查询,如下所示。 如何从查询结果中删除空值? 所以只留下一行

SELECT
    CASE
WHEN department = 'РФ' THEN
    avg_time
END AS `РФ`,
 CASE
WHEN department = 'ЕС' THEN
    avg_time
END AS `ЕС`,
 CASE
WHEN department = 'Аутсорс' THEN
    avg_time
END AS `Аутсорс`
FROM
    (
        SELECT
            department,
            (sum(apruv) / count(*) * 100) AS avg_time
        FROM
            report_designer
        WHERE TIMESTAMPDIFF(
            MINUTE,
            createdtime_spec,
            first_status_change
        ) <= 15
        GROUP BY
            department
    ) x

查询结果为result

如何从查询结果中删除空值? 所以只留下一行

1 个答案:

答案 0 :(得分:1)

一种方法是使用:

SELECT 
    (SELECT (sum(apruv) / count(*) * 100) AS avg_time
    FROM report_designer
    WHERE TIMESTAMPDIFF(MINUTE,createdtime_spec,first_status_change) <= 15
      AND department = 'РФ') AS `РФ`,
    (SELECT (sum(apruv) / count(*) * 100) AS avg_time
    FROM report_designer
    WHERE TIMESTAMPDIFF(MINUTE,createdtime_spec,first_status_change) <= 15
      AND department = 'EC') AS `EC`,
    (SELECT (sum(apruv) / count(*) * 100) AS avg_time
    FROM report_designer
    WHERE TIMESTAMPDIFF(MINUTE,createdtime_spec,first_status_change) <= 15
      AND department = 'Аутсорс') AS `Аутсорс`;