When I execute the following Code, I get the error message "Unknown column 'B.AJ' in 'having clause'". I expect that the column can be found (like in the GROUP BY clause or in the examples below) and the sql query can be executed properly.
If I delete the HAVING clause completely, the statement gets executed, so it knows the column name in the group by clause.
Additionally, If I use SUM(B.AJ) (and SUM(C.AJ)) instead, everything works fine and the query can be executed.
If I use the exact same condition in a WHERE clause, it also works properly: