I have a table called check_n where I have city & value
I wrote a query which has CASE statements in it. Below is my query
select city,
CASE when (value/10)::integer = 2
then 2 END as a,
CASE when (value/10)::integer = 5
then 5 END as b,
CASE when (value/10)::integer = 3
then 3 END as c
from check_n;
Attaching the output in below image
I want output as below:
city, a, b, c
glb, 2, 5, 3
Any help is appreciated. I'm using Postgresql 9.5
Also How to use the function if I have another table chck_n like :
city | fact | value
------+--------+-------
glb | male | 22000
glb | female | 23000
glb | total | 45000
And I want to use this query:
SELECT city,
CASE WHEN fact = 'male'
THEN value
END as males,
CASE WHEN fact= 'female'
THEN value
END as females,
CASE WHEN fact ='total'
THEN value
END as total
FROM chck_n;
valuesimultaneously be equal to 2, 5, and 3? Please show us sample data, along with the output you expect.