Pacific-Design.com

    
Home Index

1. SQL Language

2. 04 CASE Statement

SQL Language / 04 CASE Statement /

SQL CASE Statement

-- How many percent is Dan's salary compate to all sale persons
SELECT 
(
  (
    SUM(CASE WHEN name LIKE 'Dan'     THEN salary ELSE 0 END) / 
    SUM(CASE WHEN name NOT LIKE 'Dan' THEN salary ELSE 0 END) 
  ) * 100

) AS percentage

FROM Salesperson