私は数分ごとにウェブサイトから株価をダウンロードするスクリプトを作った。SQLグループと計算Avergares
私はダウンロードした瞬間に株式「FAV」の最高入札価格、最低尋ねる平均入札価格、入札単価を返すクエリを作成しようとしていましたが、私はそれらを「時間」でグループ化しようとしました。
+-----+------------+-------+------+---------+----------+-------+
| id | date | time | type | company | quantity | price |
+-----+------------+-------+------+---------+----------+-------+
| 7 | 2017-08-08 | 94827 | ask | BCQ | 30000 | 0.4 |
| 8 | 2017-08-08 | 94827 | ask | BCQ | 87211 | 0.5 |
| 9 | 2017-08-08 | 94827 | ask | BCQ | 10658 | 0.4 |
| 10 | 2017-08-08 | 94827 | ask | BCQ | 20000 | 0.39 |
| 15 | 2017-08-08 | 94827 | ask | FAV | 2600 | 1.9 |
| 16 | 2017-08-08 | 94827 | ask | FAV | 3000 | 1.83 |
| 17 | 2017-08-08 | 94827 | ask | FAV | 556 | 1.88 |
| 18 | 2017-08-08 | 94827 | ask | FAV | 845 | 1.82 |
| 19 | 2017-08-08 | 94827 | ask | FAV | 845 | 1.82 |
| 20 | 2017-08-08 | 94827 | ask | FAV | 1249 | 1.9 |
| 21 | 2017-08-08 | 94827 | ask | FAV | 4024 | 1.9 |
| 37 | 2017-08-08 | 94827 | bid | FAV | 10000 | 1.65 |
| 38 | 2017-08-08 | 94827 | bid | FAV | 655 | 1.73 |
| 39 | 2017-08-08 | 94827 | bid | FAV | 5000 | 1.7 |
| 40 | 2017-08-08 | 94827 | bid | FAV | 2102 | 1.65 |
| 41 | 2017-08-08 | 94827 | bid | FAV | 618 | 1.75 |
| 42 | 2017-08-08 | 94827 | bid | FAV | 10000 | 1.75 |
| 43 | 2017-08-08 | 94827 | bid | FAV | 150 | 1.8 |
| 52 | 2017-08-08 | 94953 | ask | BCQ | 30000 | 0.4 |
| 53 | 2017-08-08 | 94953 | ask | BCQ | 87211 | 0.4 |
| 54 | 2017-08-08 | 94953 | ask | BCQ | 10658 | 0.4 |
| 55 | 2017-08-08 | 94953 | ask | BCQ | 20000 | 0.4 |
| 60 | 2017-08-08 | 94953 | ask | FAV | 2600 | 1.9 |
| 61 | 2017-08-08 | 94953 | ask | FAV | 3000 | 1.83 |
| 62 | 2017-08-08 | 94953 | ask | FAV | 556 | 1.88 |
| 63 | 2017-08-08 | 94953 | ask | FAV | 845 | 1.82 |
| 64 | 2017-08-08 | 94953 | ask | FAV | 845 | 1.82 |
| 65 | 2017-08-08 | 94953 | ask | FAV | 1249 | 1.9 |
| 66 | 2017-08-08 | 94953 | ask | FAV | 4024 | 1.9 |
| 82 | 2017-08-08 | 94953 | bid | FAV | 10000 | 1.65 |
| 83 | 2017-08-08 | 94953 | bid | FAV | 655 | 1.73 |
| 84 | 2017-08-08 | 94953 | bid | FAV | 5000 | 1.7 |
| 85 | 2017-08-08 | 94953 | bid | FAV | 2102 | 1.8 |
| 86 | 2017-08-08 | 94953 | bid | FAV | 618 | 1.75 |
| 87 | 2017-08-08 | 94953 | bid | FAV | 10000 | 2 |
| 88 | 2017-08-08 | 94953 | bid | FAV | 150 | 1.8 |
| 97 | 2017-08-08 | 95053 | ask | BCQ | 30000 | 0.45 |
| 98 | 2017-08-08 | 95053 | ask | BCQ | 87211 | 0.4 |
| 99 | 2017-08-08 | 95053 | ask | BCQ | 10658 | 0.5 |
| 100 | 2017-08-08 | 95053 | ask | BCQ | 20000 | 0.4 |
| 105 | 2017-08-08 | 95053 | ask | FAV | 2600 | 1.9 |
| 106 | 2017-08-08 | 95053 | ask | FAV | 3000 | 1.83 |
| 107 | 2017-08-08 | 95053 | ask | FAV | 556 | 1.88 |
| 108 | 2017-08-08 | 95053 | ask | FAV | 845 | 1.82 |
| 109 | 2017-08-08 | 95053 | ask | FAV | 845 | 1.82 |
| 110 | 2017-08-08 | 95053 | ask | FAV | 1249 | 1.9 |
| 111 | 2017-08-08 | 95053 | ask | FAV | 4024 | 1.9 |
| 127 | 2017-08-08 | 95053 | bid | FAV | 10000 | 1.65 |
| 128 | 2017-08-08 | 95053 | bid | FAV | 655 | 1.89 |
| 129 | 2017-08-08 | 95053 | bid | FAV | 5000 | 1.7 |
| 130 | 2017-08-08 | 95053 | bid | FAV | 2102 | 1.65 |
| 131 | 2017-08-08 | 95053 | bid | FAV | 618 | 1.75 |
| 132 | 2017-08-08 | 95053 | bid | FAV | 10000 | 1.95 |
| 133 | 2017-08-08 | 95053 | bid | FAV | 150 | 1.8 |
+-----+------------+-------+------+---------+----------+-------+
がしかし期待される結果を提供していません。このクエリは、それだけではないの時間で、一日あたりの平均値が得られます。このようなテーブルから
+------------+--------+------------+-------------+---------+---------+
| date | time | lowest_ask | highest_bid | avg_ask | avg_bid |
+------------+--------+------------+-------------+---------+---------+
:これは私が何をしたいです日:関係なく、一日の...
select
date,
time,
(select min(price) from monitor where type = "ask") as lowest_ask,
(select max(price) from monitor where type = "bid") as highest_bid,
(select avg(price) from monitor where type = "ask") as avg_ask,
(select avg(price) from monitor where type = "bid") as avg_bid
from monitor where date = date("now") and company = "FAV"
group by time
同様にgroup by句で日付を追加するのはどうでしょうか。 –
日にちや日にちに関係なく時間別に価格を求めていますか? – xQbert
あなたの質問を編集し、希望の結果を提供してください。私はこれが意味するものを理解できません:「ダウンロードした瞬間に最高入札、最低尋ね、在庫の平均尋ねと入札をFAV」に返します。 –