Management & CommerceVery hardBusiness analyst · SQL test

Table logins(cust, dt, device) has rows: (A, 3 Jan, web), (A, 9 Jan, app), (B, 5 Jan, app), (B, 5 Jan, web), (C, 7 Jan, app), (A, 12 Jan, app). A query keeps rows where ROW_NUMBER() OVER (PARTITION BY cust ORDER BY dt DESC, device) = 1. How many rows remain, and how many of them have device = 'app'?

  1. A. 3 rows, 2 of them 'app'
  2. B. 4 rows, 3 of them 'app'
  3. C. 3 rows, all 'app'
  4. D. 6 rows, 4 of them 'app'

Correct answer: C. 3 rows, all 'app'

ROW_NUMBER gives exactly one row per customer with number 1: A's latest (12 Jan, app), C's only row (app), and for B the 5 Jan tie is broken by device in alphabetical order, so 'app' comes before 'web'. Hence 3 rows, all 'app'. RANK would have kept both of B's tied rows.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic