回答編集履歴

1

chousei

2022/12/07 08:02

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -6,3 +6,27 @@
6
6
  and t2.meta_key='延長期限'
7
7
  where t1.meta_key='有効期限'
8
8
  ```
9
+
10
+ # 追記
11
+ 有効期限化延長期限が本日よりあとで、statusがpublishなデータ
12
+ ```SQL
13
+ select * from wp_postmeta as t1
14
+ inner join wp_posts as t2
15
+ on t1.post_id=t2.id and t2.post_status='publish'
16
+ left join wp_postmeta as t3
17
+ on t1.post_id=t3.post_id
18
+ and t3.meta_key='延長期限'
19
+ where t1.meta_key='有効期限'
20
+ and (t1.meta_value>curdate() or t3.meta_value>curdate())
21
+ ```
22
+ 上記からidだけをとりだすなら
23
+ ```SQL
24
+ select t1.post_id from wp_postmeta as t1
25
+ inner join wp_posts as t2
26
+ on t1.post_id=t2.id and t2.post_status='publish'
27
+ left join wp_postmeta as t3
28
+ on t1.post_id=t3.post_id
29
+ and t3.meta_key='延長期限'
30
+ where t1.meta_key='有効期限'
31
+ and (t1.meta_value>curdate() or t3.meta_value>curdate())
32
+ ```