Use of UNION statement with aggregation functions e.g GROUP BY

Hi,
I have a question about further usage of UNION - as in course I only saw example of using UNION without any aggregation functions.
For example can you write below kind of query using UNION and GROUP BY?

> SELECT id,sum(total_trips)
> 
> FROM riders
> 
> GROUP BY id
> 
> HAVING sum(total_trips)<500;
> 
> UNION
> 
> SELECT id,sum(total_trips)
> 
> FROM riders2
> 
> GROUP BY id
> 
> HAVING sum(total_trips)<500;