Druid SQL: filter on result of expression

I have HTTP access log data in a Druid data source, and I want to see access patterns based on certain identifiers in the URL path. I wrote this query, and it works fine:


This is a companion discussion topic for the original entry at https://stackoverflow.com/questions/71998891/druid-sql-filter-on-result-of-expression