質問するログイン新規登録

回答編集履歴

4

追記

2019/07/05 07:21

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -9,4 +9,5 @@
9
9
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
10
10
  -- 2日前のtodays_close > ago_closeが存在
11
11
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
12
- ```
12
+ ```
13
+ ※特定期間の最新データとしたい場合は、期間の条件を追加

3

訂正

2019/07/05 07:21

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -1,6 +1,6 @@
1
1
  > 最新のデータから3日連続todays_close > ago_closeとなっているものの最新の値を表示したい
2
2
  ```SQL
3
- select sc, max(volume) as maxVol
3
+ select *
4
4
  from table1 as t1
5
5
  WHERE todays_close > ago_close
6
6
  -- 最新データ
@@ -9,5 +9,4 @@
9
9
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
10
10
  -- 2日前のtodays_close > ago_closeが存在
11
11
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
12
- GROUP BY SC
13
12
  ```

2

推敲

2019/07/05 07:18

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -5,9 +5,9 @@
5
5
  WHERE todays_close > ago_close
6
6
  -- 最新データ
7
7
  and not exists(select 1 from table1 where SC=t1.SC and t1.date<date)
8
- -- 1日前のtodays_close > ago_closeが存在するか
8
+ -- 1日前のtodays_close > ago_closeが存在
9
9
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
10
- -- 2日前のtodays_close > ago_closeが存在するか
10
+ -- 2日前のtodays_close > ago_closeが存在
11
11
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
12
12
  GROUP BY SC
13
13
  ```

1

訂正

2019/07/05 07:01

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -6,8 +6,8 @@
6
6
  -- 最新データ
7
7
  and not exists(select 1 from table1 where SC=t1.SC and t1.date<date)
8
8
  -- 1日前のtodays_close > ago_closeが存在するか
9
- and exists(select 1 from table1 where todays_close > ago_close and date=t1.date - interval 1 days)
9
+ and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
10
10
  -- 2日前のtodays_close > ago_closeが存在するか
11
- and exists(select 1 from table1 where todays_close > ago_close and date=t1.date - interval 2 days)
11
+ and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
12
12
  GROUP BY SC
13
13
  ```