SELECT Xian,Name,XieYBH,FactoryName,BusinessName,JiJPM,FenDMC,JiJXH,sale, CASE WHEN sale < (PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - 1.5 * (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH))) OR sale > (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) + 1.5 * (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH))) THEN 'Outlier' ELSE 'Normal' END AS OutlierIndicator FROM tmp_apply GROUP BY Xian,Name,XieYBH,FactoryName,BusinessName,JiJPM,FenDMC,JiJXH,sale WHERE OutlierIndicator = 'Outlier';关键字 'WHERE' 附近有语法错误。
时间: 2023-11-21 17:05:30 浏览: 108
这个 SQL 查询有一些语法错误。在 GROUP BY 子句后面不能再跟 WHERE 子句,应该使用 HAVING 子句。正确的查询应该是这样的:
```
SELECT
Xian,
Name,
XieYBH,
FactoryName,
BusinessName,
JiJPM,
FenDMC,
JiJXH,
sale,
CASE
WHEN sale < (PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - 1.5 * (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH)))
OR sale > (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) + 1.5 * (PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH) - PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY sale) OVER (PARTITION BY FactoryName, JiJXH)))
THEN 'Outlier'
ELSE 'Normal'
END AS OutlierIndicator
FROM tmp_apply
GROUP BY Xian, Name, XieYBH, FactoryName, BusinessName, JiJPM, FenDMC, JiJXH, sale
HAVING OutlierIndicator = 'Outlier';
```
阅读全文