LEFT JOIN statistic.video_position_history AS vh
ON (vr.language = vh.language
AND vr.country_id = vh.country_id
AND vr.device = vh.device
AND vr.tag_id = vh.tag_id
AND vr.video_id = vh.video_id)
WHERE vh IS NOT NULL
AND vr.language = ?0
AND vr.country_id = ?1
AND vr.device = ?2
AND vr.tag_id = ?3
AND vh.page = ?4
AND vh."limit" = ?5
AND vh."offset" IN (?6)
GROUP BY vh.offset
ORDER BY vh.time DESC, vr.rate DESC
короче типа такого SELECT DISTINCT ON (vh.offset) vr.rate FROM statistic.video_rate vr LEFT JOIN statistic.video_position_history AS vh ON (vr.language = vh.language AND vr.country_id = vh.country_id AND vr.device = vh.device AND vr.tag_id = vh.tag_id AND vr.video_id = vh.video_id) WHERE vh IS NOT NULL AND vr.language = ?0 AND vr.country_id = ?1 AND vr.device = ?2 AND vr.tag_id = ?3 AND vh.page = ?4 AND vh."limit" = ?5 AND vh."offset" IN (?6) ORDER BY vh.time DESC, vr.rate DESC
Обсуждают сегодня