So, if you have a Sales table with customer_id, Date2, and sale, you can summarize by week like this:SELECT FROM_DAYS(TO_DAYS(Date2) -MOD(TO_DAYS(Date) -1, 7)) week_beginning, COUNT(*) num_transactions, COUNT(DISTINCT customer_id) num_customers, SUM(sale) total_sales FROM sales GROUP BY FROM_DAYS(TO_DAYS(Date2) -MOD(TO_DAYS(Date) -1, 7))这将显示每个日历周开始的星期日的日期.如果您想要每个日历周结束的星期六,请改用它.This will show the date of the Sunday that begins each calendar week. If you want the Saturday that ends each calendar week, use this instead.SELECT FROM_DAYS(TO_DAYS(Date2) -MOD(TO_DAYS(Date) -1, 7)) + INTERVAL 6 DAY week_ending, COUNT(*) num_transactions, ...我在这里详细写了这个:http://www.plumislandmedia.net/mysql/sql-reporting-time-intervals/I have written this up in detail here: http://www.plumislandmedia.net/mysql/sql-reporting-time-intervals/你可以 这篇关于将日期转换为周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 19:25