Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Location
    Netherlands
    Posts
    58

    Question Unanswered: GROUP BY 0 > weeknumber

    This is my query, it now displays per SUM per week:
    Code:
    ROUND(SUM(IF(plt_id.dikte_gemeten > 0, plt_afm.aantal * plt_afm.lengte * plt_afm.breedte * plt_id.dikte_gemeten * kwal.soortelijk_gew / 1000000000, plt_afm.aantal * plt_afm.lengte * plt_afm.breedte * plt_id.dikte * kwal.soortelijk_gew / 1000000000)),1) AS gewicht,
    SUM(IF(plt_id.dikte_gemeten > 0, plt_afm.aantal * plt_afm.lengte * plt_afm.breedte * plt_id.dikte_gemeten * kwal.soortelijk_gew / 1000000000, plt_afm.aantal * plt_afm.lengte * plt_afm.breedte * plt_id.dikte * kwal.soortelijk_gew / 1000000000) * plt_id.prijs_per_ton) AS totaal,
    WEEK(plt_nr.updated) AS week,
    YEAR(plt_nr.updated) AS jaar
    FROM plaatregistratie_afm AS plt_afm
    LEFT JOIN plaatregistratie_nr AS plt_nr
    ON plt_nr.id = plt_afm.plaat_nr_id
    LEFT JOIN plaatregistratie_id AS plt_id
    ON plt_id.id = plt_nr.plaat_id_id
    LEFT JOIN kwaliteit AS kwal
    ON plt_id.kwaliteit_id = kwal.id
    LEFT JOIN kwaliteit_opp AS kwal_opp
    ON plt_id.kwaliteit_opp_id = kwal_opp.id
    LEFT JOIN kwaliteit_groep AS kwal_groep
    ON kwal.groep_id = kwal_groep.id
    WHERE plt_afm.id = (SELECT MAX(id) FROM plaatregistratie_afm WHERE plaat_nr_id = plt_nr.id)
    ".$where."
    GROUP BY WEEK(plt_nr.updated),
    	YEAR(plt_nr.updated)
    How should I change my query to be able to seen the SUM not per week but untill week. So like:
    >= week 1
    >= week 2
    >= week 3
    >= week 4
    etc.

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Do you mean keeping a running total? There is no way of doing this in a single SQL statement but this could be done programmatically i.e. as you are outputting the results you keep track of the sales per week and add them up and display.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Dec 2008
    Location
    Netherlands
    Posts
    58
    Thx for pointing this out. That saved me an lot of trying.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •