У меня есть сводный запрос, который выглядит как показано ниже, получая count
и AVG
строк, которые работают просто отлично, но не стандартное отклонение, STD
.
Как я могу изменить SQLниже, чтобы получить STD
?
SELECT mid as mID,
round((x.qty_sum / x.qty_count), 5) as qtAVG,
round(x.qty_stddev, 5) as qtSTDDEV,
x.qty_count as qtCOUNT,
round((x.rel_sum / x.rel_count), 5) as relAVG,
round(x.rel_stddev, 5) as relSTDDEV,
x.rel_count as relCOUNT,
FROM (SELECT mid,
SUM(CASE WHEN (mt = "qt") THEN 1 ELSE 0 END) as qty_count,
SUM(CASE WHEN (mt = "qt") THEN rt ELSE 0 END) as qty_sum,
STD(CASE WHEN (mt = "qt") THEN rt ELSE 0 END) as qty_stddev
SUM(CASE WHEN (mt = "rel") THEN 1 ELSE 0 END) as rel_count,
SUM(CASE WHEN (mt = "rel") THEN rel ELSE 0 END) as rel_sum,
STD(CASE WHEN (mt = "rel") THEN rel ELSE 0 END) as rel_stddev
FROM t_r
GROUP BY mid) x;