Infernale

The Easy City 1 [NCTU Floor 22]

Dec 21st, 2019
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.73 KB | None | 0 0
  1. # 7) Using regex to select city starts with all letters and ends with vowels
  2. SELECT COUNT(city) - COUNT(DISTINCT city)
  3.     FROM citytable WHERE city RLIKE '^[nz].*[^aiueo]$'
  4.         AND lat > 121.5 AND lon < 25.3;
  5.  
  6. # 8) Update lat to p*lat, lon to q*lon using parity checking
  7. UPDATE citytable
  8.     SET lat = lat*2, lon = lon*5
  9.     WHERE CASE
  10.         WHEN 'od' = 'ev' THEN (id % 2) = 0
  11.         ELSE id % 2 = 1 END;
  12.        
  13. # 9) Find sum of lat, lon, and difference between biggest and smallest city
  14. SELECT ROUND(SUM(lat), 3), ROUND(SUM(lon), 3), MAX(LENGTH(city)) - MIN(LENGTH(city))
  15.     FROM (SELECT*FROM citytable
  16.             WHERE CASE
  17.                 WHEN 'even' = 'even' THEN (id % 2) = 0
  18.                 ELSE id % 2 = 1 END
  19.             ORDER BY LENGTH(city) DESC, city DESC LIMIT 5) AS newTable;
Add Comment
Please, Sign In to add comment