回答編集履歴

4

追記

2019/07/05 07:21

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -21,3 +21,5 @@
21
21
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
22
22
 
23
23
  ```
24
+
25
+ ※特定期間の最新データとしたい場合は、期間の条件を追加

3

訂正

2019/07/05 07:21

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```SQL
4
4
 
5
- select sc, max(volume) as maxVol
5
+ select *
6
6
 
7
7
  from table1 as t1
8
8
 
@@ -20,6 +20,4 @@
20
20
 
21
21
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
22
22
 
23
- GROUP BY SC
24
-
25
23
  ```

2

推敲

2019/07/05 07:18

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -12,11 +12,11 @@
12
12
 
13
13
  and not exists(select 1 from table1 where SC=t1.SC and t1.date<date)
14
14
 
15
- -- 1日前のtodays_close > ago_closeが存在するか
15
+ -- 1日前のtodays_close > ago_closeが存在
16
16
 
17
17
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
18
18
 
19
- -- 2日前のtodays_close > ago_closeが存在するか
19
+ -- 2日前のtodays_close > ago_closeが存在
20
20
 
21
21
  and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
22
22
 

1

訂正

2019/07/05 07:01

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -14,11 +14,11 @@
14
14
 
15
15
  -- 1日前のtodays_close > ago_closeが存在するか
16
16
 
17
- and exists(select 1 from table1 where todays_close > ago_close and date=t1.date - interval 1 days)
17
+ and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 1 days)
18
18
 
19
19
  -- 2日前のtodays_close > ago_closeが存在するか
20
20
 
21
- and exists(select 1 from table1 where todays_close > ago_close and date=t1.date - interval 2 days)
21
+ and exists(select 1 from table1 where todays_close > ago_close and SC=t1.SC and date=t1.date - interval 2 days)
22
22
 
23
23
  GROUP BY SC
24
24