Das Zauberwort heißt Common Table Expressions oder Verschachtelte Sub-Selects.
Das Ganze geht auch im interaktiven SQL.

With x as (Select ...)
Select Count(*) From x

oder

Select Count(*)
From (Select .... From ...) x

Birgitta