Exactly what the error message says. In your (simplified) request:
SELECT SUM(`quant`), MONTH(`date`) AS month, `id`
from (
... inner select
)
group by id, month;
You did not specify an alias for the view. Therefore, it should be:
SELECT SUM(`quant`), MONTH(`date`) AS month, `id`
from (
... inner select
) as t
group by id, month;
Btw: parentheses around select parts of a pool are completely useless. I suggest removing them for clarity:
SELECT SUM(`quant`), MONTH(`date`) AS month, `id`
from (
SELECT `date`, `id`, count(`hit`) AS `quant ` FROM `stat_2014_07` WHERE `k_id` = '123'
UNION ALL
SELECT `date`, `id`, count(`hit`) AS `quant ` FROM `stat_2014_08` WHERE `k_id ` = '123'
) as t
group by id, month;
source
share