-1

我必须使用下面的查询来获取今天的计数值。

select *
from orders 
where status='P' 
AND DATE_FORMAT(FROM_UNIXTIME(date),'%Y-%m-%d')=CURDATE();

它已成功显示计数值。但是获取本月的计数值意味着必须使用以下查询。

select * from xcart_orders where status='C' AND DATE_FORMAT(FROM_UNIXTIME(date),'%m')=DATE_FORMAT(CURDATE(),'%m');

它成功显示正确的计数值。

如何获取本周的计数值..请帮助我。如何编写本周的查询

4

3 回答 3

0

The following works for me, try it and let me know

SELECT * FROM TABLE_NAME WHERE date_format(FROM_UNIXTIME(date_field), '%u')=date_format(now(), '%u')
于 2013-01-09T11:49:35.857 回答
0

您需要删除:

DATE_FORMAT(FROM_UNIXTIME(date),'%Y-%m-%d')= (MONTH(date)

您的查询应该是:

select * 
from orders 
where status='P' AND 
(MONTH(FROM_UNIXTIME(date)) = MONTH(CURDATE()) AND 
(YEAR(date) = YEAR(CURDATE());
于 2012-08-09T04:54:41.043 回答
0

只需稍微修改您的查询,这应该可以工作:

select * from orders 
where status='P'
AND MONTH(date) = MONTH(CURDATE()) 
AND YEAR(date) = YEAR(CURDATE());

您可以将其重写为:

select * from orders 
where status='P'
AND EXTRACT(YEAR_MONTH FROM date) = EXTRACT(YEAR_MONTH FROM NOW())
于 2012-08-09T04:54:49.893 回答