回答編集履歴
4
推敲
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
select target_date
|
6
6
|
|
7
|
-
, exists(select 1 from 商品履歴テーブル WHERE 購入日=target_date)
|
7
|
+
, exists(select 1 from 商品履歴テーブル WHERE 購入日=tmp.target_date)
|
8
8
|
|
9
9
|
from (
|
10
10
|
|
3
修正
test
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
|
11
11
|
select cast('1993-01-02' as date) target_date
|
12
12
|
|
13
|
-
union all select cast('1993-01-0
|
13
|
+
union all select cast('1993-01-05' as date)
|
14
14
|
|
15
|
-
union all select cast('1993-01-0
|
15
|
+
union all select cast('1993-01-08' as date)
|
16
16
|
|
17
17
|
) as tmp
|
18
18
|
|
2
修正
test
CHANGED
@@ -1 +1,19 @@
|
|
1
|
-
|
1
|
+
単に日付を基準としてという事なら、基準となる表が必要です
|
2
|
+
|
3
|
+
```SQL
|
4
|
+
|
5
|
+
select target_date
|
6
|
+
|
7
|
+
, exists(select 1 from 商品履歴テーブル WHERE 購入日=target_date)
|
8
|
+
|
9
|
+
from (
|
10
|
+
|
11
|
+
select cast('1993-01-02' as date) target_date
|
12
|
+
|
13
|
+
union all select cast('1993-01-02' as date)
|
14
|
+
|
15
|
+
union all select cast('1993-01-02' as date)
|
16
|
+
|
17
|
+
) as tmp
|
18
|
+
|
19
|
+
```
|
1
修正
test
CHANGED
@@ -1,19 +1 @@
|
|
1
|
-
質問
|
1
|
+
質問の意図と違っているみたいなので、編集中
|
2
|
-
|
3
|
-
```SQL
|
4
|
-
|
5
|
-
select * from 商品履歴テーブル WHERE 購入日='1993-01-02' or 購入日='1993-01-05' or 購入日='1993-01-08'
|
6
|
-
|
7
|
-
```
|
8
|
-
|
9
|
-
のようにします。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
でも`In`を使用する方が簡潔になります。
|
14
|
-
|
15
|
-
```SQL
|
16
|
-
|
17
|
-
select * from 商品履歴テーブル WHERE 購入日 in ('1993-01-02', '1993-01-05','1993-01-08')
|
18
|
-
|
19
|
-
```
|