SELECT SUM(`amount_sale`)as total FROM`sales`WHERE`payment_type`='Account'GROUPBY WEEK(FROM_UNIXTIME(`the_date`))ref stackoverflow