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

raggruppamento mysql per settimana

Se memorizzi the_date come intero, devi prima convertirlo in datetime usando FROM_UNIXTIME funzione:

 SELECT SUM(`amount_sale`) as total 
FROM `sales` 
WHERE `payment_type` = 'Account' 
GROUP BY WEEK(FROM_UNIXTIME(`the_date`))  

AGGIORNAMENTO :
Inoltre, potresti voler emettere il numero della settimana,

SELECT CONCAT('Week ', WEEK(FROM_UNIXTIME(`the_date`))) as week_number,
SUM(`amount_sale`) as total 
FROM `sales` 
WHERE `payment_type` = 'Account' 
GROUP BY WEEK(FROM_UNIXTIME(`the_date`))