0
嗨即时通讯设法获得一个给定时间段的网上商店月销售 我使用unix时代(时间())在表中存储销售日期在给定的时间段内按月分组查询结果
卖表看起来像这样
+-----------+---------------------+---------+----------+
| id | product_id | price | date |
+-----------+---------------------+---------+----------+
| 1 | 20 | 2000 |1323299365|
+-----------+---------------------+---------+----------+
| 2 | 28 | 3500 |1323297389|
+-----------+---------------------+---------+----------+
我想findout每月出售的给定时间内像
$from="3/2011";
$to ="4/2011";
我知道如何改变这些日期到UNIX timestam p和由像得到的结果是
//explode from
//$from = maketime(x,x,x,x,x);
//explode to
//$to= maketime(x,x,x,x,x);
$query = "select * from `sold_table` where date > $from and `date` < $to ";
,但我想要的是组结果按月所以我可以有每月静 我知道这查询不工作,但我想是这样的
$query = "select sum(`price of each month`) from `sold_table` where date > $from and `date` < $to group by month ";
,所以我可以有像
march(03) = 25000$;
april(04) = 200$ ;
我可以通过组每30天结果的结果,但我认为应该有一个更清洁的方式
也许我可以找到一个月之间的时间,如1323299365和1323297389,然后得到每个月的月销售?但我不知道豪两个时代之间的时间每月提取
似乎没有直接从Unix时间戳中提取月份等日期部分的方法。所以你需要做两件事:1)从Unix时间戳转换,2)提取日期分组的必要部分。做后者的一种方式就像在Peter Krejci的答案中一样,替代方法可以在这里找到:[MySQL查询GROUP BY日/月/年](http://stackoverflow.com/questions/508791/mysql-query-group-by -日月年)。 – 2012-01-07 20:34:10