JackSevelle Posted July 7, 2007 Share Posted July 7, 2007 Hey all, I've got a table with the following columns: DATE EVENT COUNT FAIL it basically keeps a track of how many times an even occurs/fails on a day, and there can be multiple events (A, B, C). 1-july A 20 34 1-july B 27 46 1-july C 26 23 2-july A 24 09 2-july B 22 19 3-july C 21 10 I wanted to write a query to give me the total sum of COUNT and FAIL for EVEN A for july-1 to july-3, I cant seem to figure out how to get MySQL to do this. I know we can get all of the rows for event A with something like: SELECT COUNT, FAIL from tbl WHERE DATE BETWEEN start AND end but how can we get MySQL to group together all the columns with the same EVENT field and sum up their COUNT and FAIL columns? Is this even possible with a single query? Any help is appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/58820-solved-mysql-grouping-and-summing/ Share on other sites More sharing options...
Wildbug Posted July 7, 2007 Share Posted July 7, 2007 SELECT SUM(count),SUM(fail) FROM tbl WHERE date=20070701 AND event='A'; # To do all of the events as such: SELECT date,event,SUM(count),SUM(fail) FROM tbl GROUP BY date,event; Link to comment https://forums.phpfreaks.com/topic/58820-solved-mysql-grouping-and-summing/#findComment-291989 Share on other sites More sharing options...
JackSevelle Posted July 8, 2007 Author Share Posted July 8, 2007 Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/58820-solved-mysql-grouping-and-summing/#findComment-292478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.