lundi 26 octobre 2015

Summing by month and year SQLite not producing correct sum

I have a table that looks like this:

The columns are labeled ptime, quantity, and sales amount.

"2015-10-15 9:50:09"    "2" "6"
"2015-10-4 10:24:48"    "3" "9"
"2015-10-8 12:45:46"    "5" "15"
"2015-10-8 9:50:09"     "3" "9"
"2015-10-8 10:24:48"    "1" "3"
"2015-10-9 12:45:46"    "2" "6"
"2015-10-20 12:45:46"   "2" "8"
"2015-10-2 23:45:52"    "2" "6"
"2015-10-8 15:21:23"    "3" "9"
"2015-10-12 21:31:47"   "2" "6"
"2015-9-6 12:50:09"     "1" "3"
"2015-9-15 16:38:21"    "1" "3"
"2015-9-2 23:45:52"     "1" "3"
"2015-9-8 15:21:23"     "1" "3"

I am using the following code to sum sales amount by month and year:

sum(SalesAmount) as SalesMonth,
strftime("%m-%Y", ptime) as 'month-year' 
from Sales
group by strftime("%m-%Y", ptime); 

However, the results I am getting show

"81"    "NULL"
"14"    "10-2015"

Which is not the correct sum for the months of September and October.

Any help is much appreciated.

Thanks.

Aucun commentaire:

Enregistrer un commentaire