mysql近七天,在MYSQL中从Now()选择最近7天

Thankyou for taking the time to look at my question.

I have this MYSQL query:

foreach( $wpdb->get_results(

"SELECT wp_pixelcart_calendar.datefield AS DATE,

IFNULL(SUM(wp_pixelcart_daily_sales.quantity),0) AS total_sales

FROM wp_pixelcart_daily_sales RIGHT JOIN wp_pixelcart_calendar ON (DATE(wp_pixelcart_daily_sales.order_date) = wp_pixelcart_calendar.datefield)

WHERE (wp_pixelcart_calendar.datefield BETWEEN (SELECT MIN(DATE(order_date)) FROM wp_pixelcart_daily_sales) AND (SELECT MAX(DATE(order_date)) FROM wp_pixelcart_daily_sales))

GROUP BY DATE"

) as $key => $row) {

echo "
". $row->DATE . "',". $row->total_sales . "],";

}

I'm having a hard time to display the last seven days from now in the query, ive been playing around with:

BETWEEN (SELECT MIN(DATE(order_date)) FROM wp_pixelcart_daily_sales) AND (SELECT MAX(DATE(order_date)) FROM wp_pixelcart_daily_sales))

To this:

BETWEEN NOW() FROM wp_pixelcart_daily_sales) AND DATE_ADD(NOW(), INTERVAL 7 DAY) FROM wp_pixelcart_daily_sales))

But this doesn't seem to work.

Any help appreciated.

Thanks

解决方案

if this is not working, returning 0 results, consider swapping the dates' range:

BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值