Ashok
Ashok

Reputation: 1

writing query for below employee table such that the out put should be

4) Employee table

Name      Location
 A              Hyd
 B              Bng
 C              Hyd
 D              Bng

The o/p should be

Name
                Hyd                 Bng
A              1                       0
B              0                       1
C              1                       0
D              0                       1

Upvotes: 0

Views: 34

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521389

We can use CASE expressions here:

SELECT
    Name,
    CASE WHEN Location = 'Hyd' THEN 1 ELSE 0 END AS Hyd,
    CASE WHEN Location = 'Bng' THEN 1 ELSE 0 END AS Bng
FROM yourTable
ORDER BY
    Name;

Upvotes: 2

Related Questions