【发布时间】:2016-01-29 15:23:35
【问题描述】:
所以,我有这个小 SQL 查询:
SELECT
COUNT( distinct (customerid)) AS cs, prod_id
FROM
(orderlines JOIN orders ON (orderlines.orderid=orders.orderid)) AS table_1
WHERE table_1.cs= 1
GROUP BY table_1.prod_id
ORDER BY cs ASC
这应该做的是计算不同的 customerid,并返回一个表,其中只包含只有不同的 customerid 的条目。
执行此操作时出现以下错误:
ERROR: column table_1.cs does not exist
LINE 6: WHERE table_1.cs= 1
^
*********Error**********
ERROR: column table_1.cs does not exist
SQL state: 42703
Character: 156
当我在这里明确定义时,它声称 cs 列不存在:
SELECT
COUNT( distinct (customerid)) AS cs, prod_id
【问题讨论】:
-
您使用有子句 GROUP BY .. HAVING COUNT( distinct (customerid))=1 过滤聚合结果
标签: sql postgresql