Correlated subqueries. Count Visits after Last Purchase Date
Problem solved.
Unfortunately ClickHouse does not support aliases for subqueries and hence referencing. So I had to find another workaround using SELECT from subquery (with LastVisitDate) LEFT JOINed with another subquery (with LastPurchase Date) containing and then using WHERE clause "LastVisitDate &lt; LastPurchaseDate".