Guest User

Untitled

a guest
Jan 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. SELECT (
  2. CASE type
  3. WHEN 0 THEN 'heroes'
  4. WHEN 1 THEN 'villains'
  5. ELSE 'neither'
  6. END
  7. ) AS MostFrequent
  8. FROM (
  9. SELECT type
  10. FROM mutants
  11. GROUP BY type
  12. ORDER BY count(*) DESC
  13. ) WHERE rownum <= 1
  14.  
  15. WITH
  16. RECOUNTS AS
  17. (
  18. SELECT
  19. NVL(COUNT(CASE TYPE WHEN 0 THEN TYPE END), 0) AS HEROES,
  20. NVL(COUNT(CASE TYPE WHEN 1 THEN TYPE END), 0) AS VILLAINS
  21. FROM MUTANTS
  22. )
  23. SELECT
  24. CASE WHEN HEROES > VILLAINS THEN 'heroes'
  25. WHEN HEROES < VILLAINS THEN 'villains'
  26. ELSE 'neither'
  27. END AS MOSTFREQUENT
  28. FROM RECOUNTS
  29.  
  30. select
  31. case when heroes > villains then 'heroes'
  32. when heroes < villains then 'villains'
  33. else 'neither'
  34. end as MostFrequent
  35. from ( select
  36. (select count(*) from mutants where type = 0) as heroes,
  37. (select count(*) from mutants where type = 1) as villains
  38. from dual)
  39. ;
Add Comment
Please, Sign In to add comment