group_cont
时间: 2024-06-13 07:02:38 浏览: 84
`group_concat`通常是一个在数据库查询中使用的函数,它用于将一组行的某个列的值合并成一个字符串,每个值之间由指定的分隔符隔开。这个函数常用于聚合数据,当你需要对数据进行汇总,并将多个字段的结果合并为单个结果时非常有用。
例如,在MySQL中,你可以这样使用:
```sql
SELECT group_concat(column_name SEPARATOR ',')
FROM table_name
WHERE condition;
```
在这里,`column_name`是你要聚合的列名,`table_name`是表的名称,`SEPARATOR`定义了合并后的值之间的分隔符,`condition`是可能的筛选条件。
如果你是在编程中提到`group_concat`,这可能指的是某些编程语言(如Python的pandas库)中的函数,用来处理数据集合并将值连接起来。
相关问题
SELECT FactoryName,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 FactoryName, JiJXH, sale;提示在当前兼容模式下不允许使用 PERCENTILE_CONT 函数。仅在 110 模式或更高模式下允许使用它。怎么修改
这个问题可以通过将数据库的兼容性级别提高到110或更高来解决。可以使用以下命令来更改数据库的兼容性级别:
```
ALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 110;
```
在这里,将“DatabaseName”替换为你的数据库名称。将兼容性级别设置为110将允许使用PERCENTILE_CONT函数。
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;如何取出异常值明细
要取出异常值明细,可以在上述SQL语句的基础上,加一个WHERE子句来筛选出OutlierIndicator为'Outlier'的记录,即:
```
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';
```
这样就可以只取出异常值的记录了。
阅读全文