I have been using the next Access Jet query to summarize my sales data by week:
SELECT Sum(sales) AS week_sales, Val(Format(date,"ww",2,2)) AS week_no
GROUP BY Val(Format(date,"ww",2,2))
ORDER BY Val(Format(date,"ww",2,2));
I am using two VB functions, VAL() and FORMAT(). In FORMAT() function I use two VB
- vbMondays set to 2 allows week counter start on mondays,
- vbFirstFourDays set to 2 allows week counting on year to start on first week with four
or more days (I could choose alternatively 1 to start on Jan 1st)
I am quite new to SQL. I want to export my database to mySQL, and I would like to express
this query on plain SQL, but I know only YEAR() and MONTH() built-in functions.
- Is there any SQL function that formats date as week ?
- Is there any way of defining a function on SQL to do that?