我不确定到底发生了什么事。
我有一个查询,得到所有销售在一个星期内有轻微故障,打破了一个星期到2,这是查询。。。
SELECT
ROUND(SUM(sell_price), 2) AS sell_price,
ROUND(SUM(buy_price/100*20), 2) AS fees,
ROUND(SUM(buy_price), 2) AS buy_price,
ROUND(SUM(sell_price/100*80 - buy_price), 2) AS margin,
time
FROM order_items
GROUP BY WEEK(FROM_UNIXTIME(time), 1)
ORDER BY WEEK(FROM_UNIXTIME(time), 1) DESC
这将输出以下内容
Sell Price Fees Buy Price Margin Date
44.01 4.46 22.30 12.91 31-12-2012
464.00 46.58 232.90 138.36 27-12-2012
313.82 31.80 159.01 92.06 10-12-2012
669.91 62.13 310.67 225.26 03-12-2012
265.88 25.57 127.84 84.87 02-12-2012
208.58 15.78 78.88 87.98 24-11-2012
176.90 16.32 81.59 59.93 01-01-2013
从表中可以看出,从2012年12月31日开始的一周内,销售额与2013年的销售额不符,因此也不会按降序返回销售额,因为2013年的销售额应显示在表的顶部。
返回的表应该看起来像。。。
Sell Price Fees Buy Price Margin Date
220.2 20.78 103.90 72.84 31-12-2012
464.00 46.58 232.90 138.36 27-12-2012
313.82 31.80 159.01 92.06 10-12-2012
669.91 62.13 310.67 225.26 03-12-2012
265.88 25.57 127.84 84.87 02-12-2012
208.58 15.78 78.88 87.98 24-11-2012
最佳答案
也许这对你有用:
SELECT
ROUND(SUM(sell_price), 2) AS sell_price,
ROUND(SUM(buy_price/100*20), 2) AS fees,
ROUND(SUM(buy_price), 2) AS buy_price,
ROUND(SUM(sell_price/100*80 - buy_price), 2) AS margin,
DATE_SUB(FROM_UNIXTIME(time), INTERVAL (DAYOFWEEK(FROM_UNIXTIME(time)) - 1) DAY) AS fdow
FROM order_items
GROUP BY fdow
ORDER BY fdow DESC