-- これまでのところ最も「いいね!」された投稿トップ10をクエリします(最新のDiscourseバージョン用)
SELECT
p.id AS post_id,
p.like_count,
CONCAT('/t/', t.slug, '/', t.id, '/', p.post_number) AS url,
t.title AS topic_title,
p.user_id,
u.username
FROM posts AS p
JOIN topics AS t ON t.id = p.topic_id
JOIN users AS u ON u.id = p.user_id
WHERE p.deleted_at IS NULL
AND t.deleted_at IS NULL
AND p.post_type = 1 -- 通常の投稿は1
ORDER BY p.like_count DESC
LIMIT 10