Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias not usable in GROUP BY #1989

Open
Tracked by #2210
snork-alt opened this issue Sep 6, 2023 · 1 comment
Open
Tracked by #2210

Alias not usable in GROUP BY #1989

snork-alt opened this issue Sep 6, 2023 · 1 comment
Labels
bug Something isn't working sql

Comments

@snork-alt
Copy link
Contributor

snork-alt commented Sep 6, 2023

The following query does not work

    SELECT
      PULocationID, DOLocationID, window_start AS day,
      pu_zones.Zone as PULocationName,
      do_zones.Zone as DOLocationName,
      AVG(fare_amount) as avg_amount
    INTO avg_fares
    FROM TUMBLE(trips, tpep_pickup_datetime, '1 DAY')
    INNER JOIN zones pu_zones ON trips.PULocationID = pu_zones.LocationID
    INNER JOIN zones do_zones ON trips.DOLocationID = do_zones.LocationID
    GROUP BY day, PULocationID, DOLocationID;

While this one does work:

    SELECT
      PULocationID, DOLocationID, window_start AS day,
      pu_zones.Zone as PULocationName,
      do_zones.Zone as DOLocationName,
      AVG(fare_amount) as avg_amount
    INTO avg_fares
    FROM TUMBLE(trips, tpep_pickup_datetime, '1 DAY')
    INNER JOIN zones pu_zones ON trips.PULocationID = pu_zones.LocationID
    INNER JOIN zones do_zones ON trips.DOLocationID = do_zones.LocationID
    GROUP BY window_start, PULocationID, DOLocationID;

GROUP BY should support using aliases as well as original field names

@snork-alt snork-alt added bug Something isn't working sql labels Sep 6, 2023
@Elsayed91
Copy link

This is standard SQL in most dialects. Consider referencing by number

   SELECT
      PULocationID, DOLocationID, window_start AS day,
      pu_zones.Zone as PULocationName,
      do_zones.Zone as DOLocationName,
      AVG(fare_amount) as avg_amount
    INTO avg_fares
    FROM TUMBLE(trips, tpep_pickup_datetime, '1 DAY')
    INNER JOIN zones pu_zones ON trips.PULocationID = pu_zones.LocationID
    INNER JOIN zones do_zones ON trips.DOLocationID = do_zones.LocationID
    GROUP BY 3, 1, 2;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql
Projects
None yet
Development

No branches or pull requests

2 participants