Advertisement
Infernale

The Median [NCTU Floor 24]

Dec 21st, 2019
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.49 KB | None | 0 0
  1. #Format : LIMIT s-1, t - (s - 1)
  2.  
  3. SELECT COALESCE(ROUND(AVG(val), 4), 'NULL')
  4.     FROM (SELECT CASE WHEN 'lon' = 'lat' THEN lat ELSE lon END AS val, @rownum:=@rownum+1 AS idx, @total_rows:=@rownum
  5.         FROM citytable x, (SELECT @rownum:=0) r
  6.         WHERE CASE WHEN 'lon' = 'lat' THEN x.lat ELSE x.lon END is NOT NULL
  7.                 AND id % 10 = 8 ORDER BY CASE WHEN 'lon' = 'lat' THEN x.lat ELSE x.lon END ASC LIMIT 34, 1667) AS y
  8.     WHERE y.idx IN(FLOOR((@total_rows + 1) / 2), FLOOR((@total_rows + 2) / 2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement