Q:

mysql how can I query a database table by day and month and produce totals

I have the following database table
"id","date_occurred","country","town","quantity"
"1","2012-06-01","England","Andover","82"
"2","2012-06-01","England","Colchester","569"
"3","2012-06-01","England","Farnham","1"
"4","2012-06-01","England","England","4"
"5","2012-06-01","England","America","13"
"6","2012-06-01","America","England","114"
"7","2012-06-02","England","Andover","4"
"8","2012-06-02","England","Colchester","207"
"9","2012-06-02","America","England","14"
"10","2012-06-03","England","Andover","3"
"11","2012-06-03","England","Colchester","72"
"12","2012-06-03","England","America","1"
"13","2012-06-03","America","England","15"
"14","2012-07-04","England","Andover","1"
"15","2012-07-04","England","Colchester","309"
"16","2012-07-04","England","America","4"
"17","2012-07-04","America","England","11"
"18","2012-08-05","England","Andover","2"
"19","2012-08-05","England","Colchester","319"
"20","2012-08-05","England","Farnham","1"
"21","2012-08-05","England","America","4"
"22","2012-08-05","America","England","25"
"23","2012-08-06","England","Andover","93"
"24","2013-06-06","England","Colchester","542"
"25","2013-06-06","England","Farnham","1"
"26","2013-06-06","England","England","4"
"27","2013-06-06","England","America","7"
"28","2013-06-06","America","England","115"

I would like to produce the following output from a query
Total sales per day per country for a given month
2012-06-01 England 669
2012-06-01 America 114
2012-06-02 England 211 

Total sales per day per town for a given month
2012-06-01 Andover 82
2012-06-02 Andover 4

I have been trying various queries with group by, sum, and count, but can't get the correct output.
any simple solutions or guidance welcome. Thanks in advance  

A:

Try this: 
Total sales per day per country for a given month:
SELECT date_occurred, country, SUM(quantity)
FROM tableA 
WHERE YEAR(date_occurred) = 2013 AND MONTH(date_occurred) = 6
GROUP BY date_occurred, country

Total sales per day per town for a given month:
SELECT date_occurred, town, SUM(quantity)
FROM tableA 
WHERE YEAR(date_occurred) = 2013 AND MONTH(date_occurred) = 6
GROUP BY date_occurred, town

