sql >> Database teknologi >  >> RDS >> Mysql

viser uge pr. dato

Tilskyndelse til at bruge WEEKDAY brug WEEKOFYEAR

SELECT WEEKOFYEAR(date) AS week, date
FROM myTable
WHERE date BETWEEN start_date AND end_date
ORDER BY week
 

OPDATERING Dette spørgsmål er kilden

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
 

OPDATERING 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

  1. Kopier tabeller med andet kolonnenavn MySQL

  2. Generer et tilfældigt tal i intervallet 1 - 10

  3. Opdater C#-klienten hver gang databasen opdateres

  4. Cross Join i Oracle