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

Gruppér efter uge og vælg poster fra den aktuelle uge

 SELECT DATE_FORMAT(cc.datefield, '%d-%b') AS DATE
        , SUM(IFNULL(cds.quantity,0)) AS total_sales 
 FROM cart_calendar cc
 INNER JOIN cart_daily_sales cds
         ON (DATE(cds.order_date) = cc.datefield)
 WHERE WEEK(cc.datefield) = WEEK(now())
 GROUP BY WEEK(cc.datefield)

Eller hvis du vil have det om dagen:

 SELECT DATE_FORMAT(cc.datefield, '%d-%b') AS DATE
        , SUM(IFNULL(cds.quantity,0)) AS total_sales 
 FROM cart_calendar cc
 INNER JOIN cart_daily_sales cds
         ON (DATE(cds.order_date) = cc.datefield)
 WHERE WEEK(cc.datefield) = WEEK(now())
 GROUP BY MOD(WEEKDAY(cc.datefield)+1,6) WITH ROLLUP



  1. Registreringsfejl php, mysql, ingen data i databasen

  2. Kan ikke installere mysql2 gem

  3. MySQL CHAR() vs T-SQL CHAR():Hvad er forskellen?

  4. MySQL hierarkisk datahjælp - Closure Table Method