回答編集履歴

1

訂正

2021/11/16 06:52

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -18,11 +18,11 @@
18
18
 
19
19
  SELECT 商品番号
20
20
 
21
- , sum(case when 登録日時 < sysdate then 1 else 0 end) as ①
21
+ , sum(case when not exists(select 1 from 商品 where 商品番号=x.商品番号 and (登録日時 > sysdate or 登録日時 is null) then 1 else 0 end) as ①
22
22
 
23
- , sum(case when 登録日時 > sysdate then 1 else 0 end) as ②
23
+ , sum(case when not exists(select 1 from 商品 where 商品番号=x.商品番号 and (登録日時 < sysdate or 登録日時 is null) then 1 else 0 end) as ②
24
24
 
25
- , sum(case when 登録日時 is not null
25
+ , sum(case when 登録日時 > sysdate
26
26
 
27
27
  and (select count(*) from 商品 where 商品番号=x.商品番号 and 登録日時 > sysdate) > 1
28
28
 
@@ -30,7 +30,9 @@
30
30
 
31
31
  then 1 else 0 end) as ③
32
32
 
33
+ , sum(case when (登録日時 > sysdate or 登録日時 is null)
34
+
33
- , sum(case when exists(select 1 from 商品 where 商品番号=x.商品番号 and 登録日時 > sysdate)
35
+ and exists(select 1 from 商品 where 商品番号=x.商品番号 and 登録日時 > sysdate)
34
36
 
35
37
  and exists(select 1 from 商品 where 商品番号=x.商品番号 and 登録日時 is null)
36
38
 
@@ -44,4 +46,6 @@
44
46
 
45
47
  HAVING COUNT(商品番号) > 1
46
48
 
49
+
50
+
47
51
  ```