Reputation: 1
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
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