7
6

More than 5 years have passed since last update.

SQLでレコードの値を縦に比較してランキングを動的に実装する

Last updated at Posted at 2012-03-16

副問い合わせでランキングを実装
着想がクール
http://codezine.jp/article/detail/460?p=2

rank.sql
SELECT P1.name,
       P1.price,
       (SELECT COUNT(P2.price)
          FROM Products P2
         WHERE P2.price > P1.price) + 1 AS rank
  FROM Products P1
 ORDER BY rank;
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6