Ну почему же итоговый ))) Если уж красиво, то (select u.id, u.phone, u.email from akson.users u order by createdAt desc limit 1 by createdAt) as users можно через запятую тоже в блок WITH вынести и будет WITH cte as (select distinct pc.createdAt as createdAt, pc.inn as inn, toUInt64((arrayJoin(mapKeys(pc.priceCategoryByStore)))) as storeId, pc.name as orgName, pc.userId as userId from akson.contractors_merged pc), users as (select u.id, u.phone, u.email from akson.users u order by createdAt desc limit 1 by createdAt) select distinct toDate(cte.createdAt) as createdAt, inn, userId, s.techName as techName, orgName, users.phone as phone, users.email as email from cte join users on userId = users.id join akson.stores s on s.id = storeId where and(cte.createdAt >= '2022-07-11', cte.createdAt <= '2022-08-08 23:59:00') order by createdAt desc LIMIT 500
Обсуждают сегодня