0
私はメダインを計算する必要がある大きなデータベースからテンポラリテーブルを作成しました。返されたクエリされたMySQL一時テーブルのメジアンを計算する方法
一時テーブルを作成するためのコードの下(それは数字で容積の21行を持っている)コードの下
CREATE TEMPORARY TABLE table1 (Select vol from EOD_PRICING where
`ticker`=16665396 order by `xdate` desc limit 21);
中央値を計算するが、上記のためにそれを行うにはどのようになっていないが、一時的なテーブル「TABLE1」
を作成しましたSELECT AVG(middle_values) AS 'median' FROM (
SELECT t1.`vol` AS 'middle_values' FROM
(
SELECT @row:[email protected]+1 as `row`, x.`vol`
FROM table1 AS x, (SELECT @row:=0) AS r
WHERE `ticker`=16665396 order by `xdate` desc limit 21
ORDER BY x.`vol`
) AS t1,
(
SELECT COUNT(*) as 'count'
FROM table1 x
WHERE `ticker`=16665396 order by `xdate` desc limit 21
) AS t2
WHERE t1.row >= t2.count/2 and t1.row <= ((t2.count/2) +1)) AS t3;
私は私の要件のためのUNION ALLでのコードの下に使用している場合、それは You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 17
CREATE TEMPORARY TABLE table1 (Select * from EOD_PRICING where
`ticker`=16665396 order by `xdate` desc limit 21)
UNION ALL
SELECT AVG(middle_values) AS 'median' FROM (
SELECT t1.`vol` AS 'middle_values' FROM
(
SELECT @row:[email protected]+1 as `row`, x.`vol`
FROM table1 AS x, (SELECT @row:=0) AS r
ORDER BY x.`vol`
) AS t1,
(
SELECT COUNT(*) as 'count'
FROM table1 x
) AS t2
WHERE t1.row >= t2.count/2 and t1.row <= ((t2.count/2) +1)) AS t3;
語ります
事前にお手伝いいただきありがとうございます。
括弧内の2番目のselect文(union all演算子の後の1つ)を置換しようとします。 –