RANK, parition by id order by value_type

0

Please login or register to vote for this query.

(click on this box to dismiss)

Science Fiction and Fantasy

Q&A for science fiction and fantasy enthusiasts

-- RANK

WITH test AS (
  SELECT 1 AS id, 'B' AS value_type
  UNION ALL
  SELECT 1, 'B'
  UNION ALL
  SELECT 1, 'A'
  UNION ALL
  SELECT 2, 'A'
  UNION ALL
  SELECT 2, 'A'),
     summary AS (
SELECT t.*,
       RANK() OVER (PARTITION BY t.id ORDER BY t.value_type DESC) AS rank
  FROM test t)
SELECT *
  FROM summary
 WHERe rank = 1

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results