Project Scenario:

When the large-screen statistics are displayed, the number of clicks per day is calculated according to the date


Problem description:


Reason analysis:

Mysql > execute SQL statements in order:

From — > WHERE — > group by — > having — > select — > order by

As you can see, select is executed after group by and having, so what’s the problem? Group by doesn’t have an alias yet, because the alias is generated in select, and select is after group by, so that’s an error

On the contrary

The hive SQL is executed in the following order:

From — > WHERE — > select — > group by — > having — > order by


Solution:

Do not use an alias for group by