我来自SQL Server,我很惊讶以下查询不起作用:
SELECT COUNT(*) as TotalOrders,
SUM(CASE WHEN NumProducts = 2 THEN 1 ELSE 0 END) as OrdersWithBothProducts,
AVG(CASE WHEN NumProducts = 2 THEN 1.0 ELSE 0 END) as Proportion_OrdersWithBothProducts,
FROM (SELECT id,
COUNT(DISTINCT CASE WHEN Product IN ('p1','p9') THEN Product END) as NumProducts
FROM OrderDetails od
GROUP BY id
) o;
其中user_job_titles包含以下列:
DELETE FROM user_job_titles WHERE id IN (
"c836d018-1d12-4507-a268-a4d80d6d3f54",
"d0961a90-7d31-4c4c-9c1b-671115e3d833",
"62dda420-6e62-4017-b41d-205c0aa82ead"
)
错误是:
id
user_id
job_title_id
我使用pgAdmin和最新的postgresql版本。有没有其他方法可以运行此查询?
答案 0 :(得分:2)
您需要使用'
DELETE FROM user_job_titles
WHERE id IN (
'c836d018-1d12-4507-a268-a4d80d6d3f54',
'd0961a90-7d31-4c4c-9c1b-671115e3d833',
'62dda420-6e62-4017-b41d-205c0aa82ead'
);
我来自SQL Server,我很惊讶看到以下查询不起作用
然后你有SET QUOTED_IDENTIFIER
AS OFF
。默认情况下为ON
。
当 SET QUOTED_IDENTIFIER为ON 时,所有字符串都由分隔 引号被解释为对象标识符。
检查:
SET QUOTED_IDENTIFIER OFF;
SELECT "A"
-- The same behaviour as in Postgresql
SET QUOTED_IDENTIFIER ON;
SELECT "A"
-- Invalid column name 'A'.
的 LiveDemo
强>
答案 1 :(得分:2)
对字符串常量使用单引号:
DELETE FROM user_job_titles
WHERE id IN ('c836d018-1d12-4507-a268-a4d80d6d3f54',
'd0961a90-7d31-4c4c-9c1b-671115e3d833',
'62dda420-6e62-4017-b41d-205c0aa82ead'
);
双引号是与表名和列名一起使用的转义字符。因此错误。