Advertisement
festinko

Untitled

Nov 11th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.74 KB | None | 0 0
  1. WITH
  2. /*List of Phone Alert Contacts*/
  3.   phoneAlertContacts as(
  4.     SELECT
  5.       userID,
  6.       alertContactID,
  7.       alertContactType,
  8.       alertContactFriendlyName,
  9.       alertContactValue,
  10.       RIGHT (alertContactValue,3) alertContactValueLastChar,
  11.       alertContactStatus
  12.    
  13.     FROM
  14.       `uptimerobot-001.ur.alertcontacts`
  15.  
  16.     WHERE
  17.       alertContactType IN (1,8,14)
  18.  
  19.   ),
  20.  
  21. /*Number of Unique Mobile App Alert Contacts per user*/
  22.   phoneAlertContactsCount as (
  23.   SELECT  
  24.     userID,
  25.     COUNT(DISTINCT alertContactValueLastChar) uniquePhoneAlertContactsCount
  26.   FROM
  27.     phoneAlertContacts
  28.   GROUP BY
  29.     userID
  30.   )
  31.  
  32. SELECT
  33.   *
  34.  
  35. FROM
  36.   phoneAlertContactsCount
  37.  
  38. ORDER BY
  39.   uniquePhoneAlertContactsCount DESC
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement