我使用此代码打印1周,但它排除了今天的价值:
DATE(post_date) = DATE(DATE_SUB(NOW(),INTERVAL 1 DAY))
查询:
SELECT sum($wpdb->postmeta.meta_value)
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.id = $wpdb->postmeta.post_id
WHERE post_status = 'publish' && post_type = 'alj_cases'
&& DATE(post_date) = DATE(DATE_SUB(NOW(),INTERVAL 1 DAY))
GROUP BY meta_key
LIKE '%negative%'
ORDER BY post_date
答案 0 :(得分:0)
如果您的目标是从上周获得帖子,则可以使用date_diff
检查发布日期和当前日期之间的差异是否不超过七天:
SELECT SUM($wpdb->postmeta.meta_value)
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.id = $wpdb->postmeta.post_id
WHERE post_status = 'publish' AND
post_type = 'alj_cases' AND
DATE_DIFF(CURRENT_DATE(), post_date) <= 7 AND
meta_key LIKE '%negative%'