Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
そこで、私が書いたカスタム投稿システム用の投票システムを構築しました。
「投票数が多い」「いいね!」などで並べ替えできるようにしたいです。
私は2つのテーブルを持っています。
エントリ: ID、タイトル、投稿
投票: ID、EntryID、結果
各エントリの投票テーブルをクエリして、投票数を確認し、各テーブルの投票数でエントリを並べ替えられるようにしたいと考えています。私は結合などをいじりましたが、それを理解できないようです。助言がありますか?
エントリ アイテムで結合とグループ化を行い、count や sum などの集計を使用して、投票数と投票の合計を取得します。
select e.ID, e.Title, e.Post, count(*) as Votes, sum(Result) as Result from Entry e inner join Vote v on v.EntryId = e.Id group by e.ID, e.Title, e.Post order by 4 desc