If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > GROUP BY 0 > weeknumber

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-11, 02:18
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Question 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.
Reply With Quote
  #2 (permalink)  
Old 04-12-11, 06:05
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 04-21-11, 15:45
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Thx for pointing this out. That saved me an lot of trying.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On