SELECT SUM(price) as price, A.date, count(A.id) as orders, (SELECT count(id) from b_orders_contact WHERE affid = and is_ready = 0 and FROM_UNIXTIME(date, '%Y%m%d') = FROM_UNIXTIME(A.date, '%Y%m%d')) as n_orders, (SELECT SUM(price) from b_orders_contact WHERE affid = and is_ready = 1 and FROM_UNIXTIME(date, '%Y%m%d') = FROM_UNIXTIME(A.date, '%Y%m%d')) as suma FROM b_orders_contact A WHERE A.affid = and FROM_UNIXTIME(A.date, '%Y%m') = 201805 GROUP by FROM_UNIXTIME(A.date, '%Y%m%d') ORDER by A.date DESC
No database