sql >> Database >  >> RDS >> Oracle

De resultaten van CASE-instructies toevoegen

Je mist de END op uw CASE uitspraken:

SELECT
  surname,
  givenname,
  (CASE WHEN surname = 'Smith' THEN 2 ELSE 0 END)  -- < add END
    + (CASE WHEN givenname = 'John' THEN 1 ELSE 0 END)  -- < add END
    AS score
FROM person
WHERE (surname = 'Smith' AND givenname LIKE 'J%')
  OR  (surname LIKE 'S%' AND givenname = 'John')
  OR  (surname = 'John' AND givenname LIKE 'S%')
  OR  (surname LIKE 'J%' AND givenname = 'Smith')
ORDER BY
  score DESC,
  surname ASC,
  givenname ASC;



  1. Hoe kan ik een specifiek record bijwerken zonder SELECT-machtiging?

  2. Tijdslimiet instellen php

  3. Hoe databasenaam opvragen in Oracle SQL Developer?

  4. MySQL Foreign Key ON DELETE CASCADE over 3 tabellen