我有疑问.. 我有数据库大多是这样的, 如何从每位客户那里获得每周平均花费?你能告诉我这个sql查询吗?
这里的例子是
$days = ceil((strtotime("4/30/2016 3AM") - time())/(60*60*24));
if ($days > "1") { echo "$days days to go"; }
elseif ($days = "1") { echo "$days day to go"; }
elseif ($days = "0") { echo "TODAY!"; }
else { echo "You're late"; }
以及更多......
谁能帮帮我?感谢答案 0 :(得分:2)
尝试对客户和一年中的一周使用GROUP BY
:
SELECT customer, WEEK(date), AVG(spending)
FROM sales
GROUP BY customer, WEEK(date)