我认为您的意思是“开始日期”是“publication_date”。
如果没有模式定义,我会猜测列名和数据类型
一种方法是在 EXISTS 谓词中使用相关子查询,尽管这可能不是最有效的方法:
SELECT p.id
FROM wp_posts p
WHERE EXISTS
( SELECT 1
FROM wp_postmeta m1
WHERE m1.wp_posts_id = p.id
AND m1.meta_option_name = 'publication date'
AND m1.meta_option_date_value <= NOW()
)
AND EXISTS
( SELECT 1
FROM wp_postmeta m2
WHERE m2.wp_posts_id = p.id
AND m2.meta_option_name = 'expiration date'
AND m2.meta_option_date_value > NOW()
)
您特别询问了使用 LEFT JOIN
使用 LEFT JOIN 操作可以获得等效的结果(尽管此查询实际上等同于进行 INNER JOIN 操作):
SELECT p.id
FROM wp_posts p
LEFT
JOIN wp_postmeta m1
ON m1.wp_posts_id = p.id
AND m1.meta_option_name = 'publication date'
AND m1.meta_option_date_value <= NOW()
LEFT
JOIN wp_postmeta m2
ON m2.wp_posts_id = p.id
AND m2.meta_option_name = 'expiration date'
AND m2.meta_option_date_value > NOW()
WHERE m1.id IS NOT NULL
AND m2.id IS NOT NULL
GROUP
BY p.id