Reputation: 151
I'm having a difficult time wrapping my head around how to properly organize this database. I have a table of 7,000,000 rows. Each row has a count, date, and a non unique name.
Example:
name -- count -- date
blue -- 27 -- 2012-9-05
red -- 12 -- 2012-10-05
blue -- 19 -- 2012-9-07
blue -- 13 -- 2012-10-4
What is the best way to store the sum of each name
for each month? If a server side language has to be used to do this, I only know PHP.
Thanks in advance!
Upvotes: 0
Views: 77
Reputation: 4171
I believe, it is better to do in the backend. e.g.
SELECT NAME,date,SUM(Count) AS SumCount
FROM <Your TABLE>
GROUP BY NAME,MONTH(date)
Upvotes: 3