Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在没有组的MIN()和MAX()的情况下获取项目组的STDDEV()_Mysql_Sql_Aggregate Functions_Standard Deviation - Fatal编程技术网

Mysql 如何在没有组的MIN()和MAX()的情况下获取项目组的STDDEV()

Mysql 如何在没有组的MIN()和MAX()的情况下获取项目组的STDDEV(),mysql,sql,aggregate-functions,standard-deviation,Mysql,Sql,Aggregate Functions,Standard Deviation,我有一张像这样的桌子 | id | user | bottle | count | | 1 | foo | beer | 2 | | 2 | bar | beer | 5 | | 3 | som1 | beer | 6 | | 4 | som2 | beer | 4 | | 5 | som1 | wine | 1 | 等等 如果没有各组(啤酒、葡萄酒等)的count值MIN()和MAX()如何获得STDDEV

我有一张像这样的桌子

| id | user | bottle |  count |
| 1  | foo  | beer   |    2   |
| 2  | bar  | beer   |    5   |
| 3  | som1 | beer   |    6   |
| 4  | som2 | beer   |    4   |
| 5  | som1 | wine   |    1   |
等等

如果没有各组(啤酒、葡萄酒等)的
count
MIN()
MAX()
如何获得
STDDEV()
i、 我该怎么去

| bottle |      stddev     |

|  beer  |stddev of 2 and 4|
?

另外,如何获得像上面这样的查询总共返回的行数

到目前为止我已经试过了

SELECT STD(count) as stddev, bottle
FROM drinks WHERE count < (
    SELECT MAX(count) FROM drinks)
              AND count > (
    SELECT MIN(count) FROM drinks)
GROUP BY bottle;
但这适用于整个表的
MAX()
,而不仅仅是
分组依据

使用聚合和联接引入极值,然后过滤它们并计算标准偏差:

select bottle, STDEV(d.count)
from drd.inks d join
     (select bottle, MIN(count) as minc, MAX(count) as maxc
      from drinks
      group by bottle
     ) dsum
     on d.bottle = dsum.bottle and
        d.count not in (dsum.minc, dsum.maxc)
group by d.bottle