在雪花中运行以下命令时出现以下错误:
“意外的Select语句”
这是我的SQL
SELECT * FROM ABC
WHERE DR2NB NOT IN ( SELECT DR2NB FROM ABC WHERE FLAG='TRUE' )
ORDER BY DR2NB
答案 0 :(得分:1)
CREATE OR REPLACE TABLE ABC (DR2NB NUMBER, FLAG VARCHAR);
INSERT INTO ABC VALUES(1,'TRUE'),(2,'FALSE'),(3,'TRUE'),(4,'FALSE'),(1,'TRUE'),(2,'FALSE'),(3,'TRUE'),(4,'FALSE');
SELECT * FROM ABC WHERE DR2NB NOT IN ( SELECT DR2NB FROM ABC WHERE FLAG='TRUE' ) ORDER BY DR2NB;
您也可以通过使用以下查询来获得所需的结果:
SELECT * FROM ABC WHERE FLAG!='TRUE' ORDER BY DR2NB;
答案 1 :(得分:0)
很难在没有数据示例的情况下建议更改,但是我建议像这样构造子查询:
With x as(SELECT DR2NB FROM ABC WHERE FLAG='TRUE' )
SELECT *
FROM ABC
WHERE
DR2NB NOT IN x
ORDER BY DR2NB;
参考: