0

I have a table set up in my database that contains the following columns: id (auto increment), date, number, comment. I am taking the data in this database and using php to plot it in highcharts as a comparison of 'number' (y axis) and 'date' (x axis). The basic functionality of this graph is complete.

In the future I could have multiple entries per date where the numbers differ. ex:

date: 02/24/2014 - number: 3
date: 02/24/2014 - number: 9

Is there any way I can search for this and add the two numbers associated with that date (so that I only have one plot per date)? My desired result (using the above example) would be

date: 02/24/2014 - number: 12

Sorry if this is confusing, im not sure quite how to explain it the best either. Please let me know if you have any suggestions or can point me somewhere.

Thanks

wakey
  • 2,283
  • 4
  • 31
  • 58

1 Answers1

2

you can use the SUM() function in combination with GROUP BY:

SELECT date, SUM(number) FROM table GROUP BY date;
chresse
  • 5,486
  • 3
  • 30
  • 47
  • Thanks that works! Is there an easy way to do this with strings too? Something like sum() that would combine two strings if they shared the same date? – wakey Jun 03 '14 at 20:36
  • 1
    Yes with the concat function ( http://stackoverflow.com/questions/149772/how-to-use-group-by-to-concatenate-strings-in-mysql ) – chresse Jun 03 '14 at 20:40