oleg-agapov / data-engineering-book

Accumulated knowledge and experience in the field of Data Engineering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Line 637, Alias in HAVING

Rytrops opened this issue · comments

Hi,

I found your beginners SQL to be very informative. While following along and practicing the examples myself I noticed an issue where one of the shown commands wasn't valid SQL syntax. On line 637 you use the alias count_users for count(id) for the Having selector. I think this may be a minor error, from what I understand SQL doesn't allow aliases in Having and you would have to use count(id) or whatever was run in Select. Or am I mistaken?

Regards,
Ryan

Hi Ryan,

Good catch!

It actually may depend on the database you are using.

In SQLite and MySQL you can use aliases in HAVING. Other databases needs to be checked.

I'll leave a version with alias until I find a counter-example. In that case I'll probably switch to full version.

Thanks for the clarification. Also thank you for creating such a wonderful guide. It's be very useful in learning SQL!