Filtering by comparing branches of a query

It would be something like this query