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

MySQL Penjualan bulanan 12 bulan terakhir termasuk bulan tanpa Penjualan

Terima kasih atas petunjuk @pankaj, Di sini saya menyelesaikannya melalui kueri ini ...

SELECT 
    SUM(IF(month = 'Jan', total, 0)) AS 'Jan',
    SUM(IF(month = 'Feb', total, 0)) AS 'Feb',
    SUM(IF(month = 'Mar', total, 0)) AS 'Mar',
    SUM(IF(month = 'Apr', total, 0)) AS 'Apr',
    SUM(IF(month = 'May', total, 0)) AS 'May',
    SUM(IF(month = 'Jun', total, 0)) AS 'Jun',
    SUM(IF(month = 'Jul', total, 0)) AS 'Jul',
    SUM(IF(month = 'Aug', total, 0)) AS 'Aug',
    SUM(IF(month = 'Sep', total, 0)) AS 'Sep',
    SUM(IF(month = 'Oct', total, 0)) AS 'Oct',
    SUM(IF(month = 'Nov', total, 0)) AS 'Nov',
    SUM(IF(month = 'Dec', total, 0)) AS 'Dec',
    SUM(total) AS total_yearly
    FROM (
SELECT DATE_FORMAT(date, "%b") AS month, SUM(total_price) as total
FROM cart
WHERE date <= NOW() and date >= Date_add(Now(),interval - 12 month)
GROUP BY DATE_FORMAT(date, "%m-%Y")) as sub


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Kesalahan MySQL 1215:Tidak dapat menambahkan batasan kunci asing

  2. Fungsi MySQL CRC32() – Contoh

  3. JSON_SET() – Masukkan atau Perbarui Nilai dalam Dokumen JSON di MySQL

  4. PDO menyiapkan pernyataan fetch() mengembalikan hasil ganda

  5. Setel Ulang Kata Sandi Root MySQL