I have the below data in table1
id | marks | total |
---|---|---|
1 | 78 | 100 |
2 | 20 | 50 |
and I know 1 -> Sam
and 2 -> Joe
I want to show
id | percentage | name |
---|---|---|
1 | 78 | Sam |
2 | 40 | Joe |
Not sure where to start when I have the id -> map as static map
Since you know 1 -> Sam and 2 -> Joe following is possible :
SELECT
id,
marks,
total,
CASE id
WHEN 1 THEN 'Sam'
WHEN 2 THEN 'Joe'
ELSE 'Unknown'
END AS name,
(marks / total) * 100.0 AS percentage
FROM
table1;