I have the following table:
CREATE TABLE trips(
trip_id int,
true_foot boolean,
true_bike boolean,
true_bus boolean,
true_car boolean,
true_metro boolean
)
INSERT INTO trips (trip_id,true_foot,true_bike,true_bus,true_car,true_metro)
VALUES
(563097,'t','f','f','f','f'),
(596303,'f','f','f','t','f'),
(595648,'f','f','f','t','f'),
(566061,'t','f','f','f','f'),
(566753,'t','f','f','f','f'),
(561179,'t','f','f','f','f'),
(535519,'f','f','f','f','f'),
(548460,'t','f','f','f','f'),
(543477,'f','f','f','t','f'),
(540797,'t','f','f','f','f')
Only one column has true value in a row (or none). Then I want to count all true values for foot, bike, bus, etc...
SELECT
COUNT(*) FILTER (WHERE true_foot IS TRUE ) AS 'walk',
COUNT(*) FILTER (WHERE true_bike IS TRUE ) AS 'bike',
COUNT(*) FILTER (WHERE true_bus IS TRUE) AS 'bus',
COUNT(*) FILTER (WHERE true_car IS TRUE) AS 'car',
COUNT(*) FILTER (WHERE true_metro IS TRUE) AS 'metro'
FROM trips
ERROR: syntax error at or near "'walk'"
LINE 3: COUNT(*) FILTER (WHERE true_foot IS TRUE ) AS 'walk',