Skip to content

Instantly share code, notes, and snippets.

@nivertech
Forked from thorwebdev/avg_fare_amount.sql
Last active August 29, 2015 14:17
Show Gist options
  • Save nivertech/9862e476139862adaff8 to your computer and use it in GitHub Desktop.
Save nivertech/9862e476139862adaff8 to your computer and use it in GitHub Desktop.
SELECT
pickup_polyId,
SUM(fare_amount)/COUNT(*) AS average_fare,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
WHERE
fare_amount!=0
GROUP BY
pickup_polyId
HAVING
no_of_trips > 100000
ORDER BY
average_fare DESC;
SELECT
pickup_polyId,
SUM(tip_amount)/COUNT(*) AS average_tip,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
WHERE
tip_amount!=0
GROUP BY
pickup_polyId
HAVING
no_of_trips > 50000
ORDER BY
average_tip DESC;
SELECT
pickup_polyId,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
GROUP BY
pickup_polyId
ORDER BY
no_of_trips DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment