In the SQL Select function , i am using count
& avg
function , hence i need to use group by function , however i am not yet understand why i need to use group by function , since i am new in sql. so can someone please explain to me the usage of groupby
function
Query:
SELECT usertype,
concat(start_station_name," to ",end_station_name) as route,
count(*) as num_trips,
round(avg(cast(tripduration AS int64)/60),2) as duration
FROM `bigquery-public-data.new_york_citibike.citibike_trips`
GROUP BY start_station_name,end_station_name,usertype
Order by num_trips DESC
LIMIT 20