Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

menampilkan minggu sesuai tanggal

Alih-alih menggunakan WEEKDAY gunakan WEEKOFYEAR

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

PERBARUI Pertanyaan ini adalah sumbernya

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

PERBARUI 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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. koneksi mysql dari domain yang berbeda

  2. tabel pivot/unpivot mysql

  3. PHP:Memasukkan Nilai dari Formulir ke MySQL

  4. R:daftar string di ifelse

  5. menampilkan data dari database ke dropdown CodeIgniter