sql中有18张表,每张表有两列,fps列和时间列,查询每张表中fps在平均值减去两倍标准差和平均值减去两倍标准差范围中平均值后
时间: 2024-06-04 09:12:10 浏览: 116
sql多表关联查询--按照文本例子即可
可以使用以下SQL语句来实现:
SELECT AVG(fps) FROM (
SELECT * FROM table1 WHERE fps BETWEEN
(SELECT AVG(fps) - 2*STDDEV_POP(fps) FROM table1)
AND
(SELECT AVG(fps) + 2*STDDEV_POP(fps) FROM table1)
UNION ALL
SELECT * FROM table2 WHERE fps BETWEEN
(SELECT AVG(fps) - 2*STDDEV_POP(fps) FROM table2)
AND
(SELECT AVG(fps) + 2*STDDEV_POP(fps) FROM table2)
UNION ALL
SELECT * FROM table3 WHERE fps BETWEEN
(SELECT AVG(fps) - 2*STDDEV_POP(fps) FROM table3)
AND
(SELECT AVG(fps) + 2*STDDEV_POP(fps) FROM table3)
...
UNION ALL
SELECT * FROM table18 WHERE fps BETWEEN
(SELECT AVG(fps) - 2*STDDEV_POP(fps) FROM table18)
AND
(SELECT AVG(fps) + 2*STDDEV_POP(fps) FROM table18)
) AS t;
这里使用了UNION ALL操作符来将18张表的结果合并成一个表,然后计算平均值。在每张表中,使用子查询来查询fps在平均值减去两倍标准差和平均值加上两倍标准差之间的数据,并将结果合并。最后在合并后的表中计算平均值。
阅读全文