December 2017
Beginner to intermediate
264 pages
5h 38m
English
The legacy SQL does not support DISTINCT. The workaround is to use the group by statement, as shown in the following query. It outputs two columns: one is the column with distinct values and second is the count of those distinct values:
#legacySQLSELECT payment_type, count(1) FROM [bigquery-public-data:chicago_taxi_trips.taxi_trips] GROUP BY payment_typeORDER BY payment_type
Standard SQL supports the DISTINCT clause and it can be used as shown here. This query returns only one column as output:
#standardSQLSELECT DISTINCT payment_typeFROM `bigquery-public-data.chicago_taxi_trips.taxi_trips`ORDER BY payment_type