Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

exibindo a semana conforme a data


Em vez de usar o WEEKDAY, use WEEKOFYEAR
SELECT WEEKOFYEAR(date) AS week, date
FROM myTable
WHERE date BETWEEN start_date AND end_date
ORDER BY week

ATUALIZAÇÃO Esta pergunta é a fonte
SELECT  (WEEK(date, 5) -
        WEEK(DATE_SUB(date, INTERVAL DAYOFMONTH(date) - 1 DAY), 5) + 1) as week, date
    FROM myTable
    WHERE date BETWEEN start_date AND end_date
    ORDER BY week

ATUALIZAÇÃO 2
SELECT  (WEEK(date, 1) -
        WEEK(DATE_SUB(date, INTERVAL DAYOFMONTH(date) - 1 DAY), 1) + 1) as week, date
    FROM myTable
    WHERE date BETWEEN start_date AND end_date
    ORDER BY week