working version of queries
CTE queries