亚马逊红移 1.0.22169
我正在尝试按公司名称排序并首先放置任何“N/A”值。我有一个简单的测试表,如下所示:
+----+-----------+
| id | name |
+----+-----------+
| 1 | Company 3 |
| 2 | Company 1 |
| 3 | N/A |
| 4 | Company 2 |
+----+-----------+
对于 MySQL,我使用以下内容:
SELECT
`name` AS 'company'
FROM
`companies`
GROUP BY
`company`
ORDER BY
CASE `company` WHEN 'N/A' THEN 1 ELSE 2 END ASC,
`company` ASC
得到想要的结果:
+-----------+
| company |
+-----------+
| N/A |
| Company 1 |
| Company 2 |
| Company 3 |
+-----------+
但是在 Redshift 中尝试这样做时:
SELECT
"name" AS "company"
FROM
"companies"
GROUP BY
"company"
ORDER BY
CASE "company" WHEN 'N/A' THEN 1 ELSE 2 END ASC,
"company" ASC
我收到以下错误:
Query 1 ERROR: ERROR: column "company" does not exist in companies
有什么建议可以调整它以适用于 PostgreSQL 吗?