channels
INNER JOIN (SELECT c.id,
row_number() over (order by last_action_at desc) AS num,
last_action_at >= (NOW() - INTERVAL '7 day') AS last_week
FROM channels c) AS stats ON channels.id = stats.id
WHERE stats.last_week is TRUE OR stats.num <= 10;
subquery если только использовать https://sequelize.org/master/manual/sub-queries.html
Обсуждают сегодня