仅当存在非null值时才如何在SQL中选择列?

时间:2019-03-04 03:21:57

标签: sql postgresql

我在Postgresql中有一列称为debt的列,该列通常包含空值。我正在使用SQL语句将数据导出到CSV文件。当debt列中至少有一个非null值时,我要导出该列。但是我希望在所有值都为null时将其隐藏。如何使用SQL完成此操作?

以下是当前声明:

COPY (
  SELECT
    e.name AS "Employee Name",
    e.title AS "Job Title",
    e.gross AS "Total Pay",
    e.total AS "Total Pay & Benefits",

    e.year AS "Year",
    e.notes AS "Notes",
    j.name AS "Agency",
    e.status AS "Status"

  FROM employee_employee e
  INNER JOIN jurisdiction_jurisdiction j on e.jurisdiction_id = j.id
  WHERE
      e.year = 2017 AND
      j.id = 564
 ORDER BY "Agency" ASC, "Total Pay & Benefits" DESC
) TO STDOUT WITH CSV HEADER;

1 个答案:

答案 0 :(得分:0)

从dbname中选择IFNULL(colname,“”)