2
I would like to perform a query About the table FICHA_EXAME with the following data:
CREATE TABLE FICHA_EXAME
(
FICHA smallint,
EXAME VARCHAR(15)
);
INSERT INTO FICHA_EXAME VALUES (1,'Hemograma');
INSERT INTO FICHA_EXAME VALUES (1,'Colesterol');
INSERT INTO FICHA_EXAME VALUES (1,'Ferro');
INSERT INTO FICHA_EXAME VALUES (2,'Colesterol');
INSERT INTO FICHA_EXAME VALUES (3,'Ferro');
INSERT INTO FICHA_EXAME VALUES (3,'Hemograma');
INSERT INTO FICHA_EXAME VALUES (4,'Ferro');
In the query I created, I would like to show which exams are contained in the extracted form through a "Has or does not Have", and not list the exam in fact, but would like it to be displayed in only 1 line.
I tried it the way below, but for each exam related to the card, brings me a new line, and I would like it to be displayed dynamically in one line only, regardless if there was more than one exam equal in the same form:
SELECT FICHA,
CASE WHEN EXAME = 'Hemograma' THEN 'S' ELSE 'N' END AS 'POSSUI HEMOGRAMA?',
CASE WHEN EXAME = 'Colesterol' THEN 'S' ELSE 'N' END AS 'POSSUI COLESTEROL?',
CASE WHEN EXAME = 'Ferro' THEN 'S' ELSE 'N 'END AS 'POSSUI FERRO?'
FROM FICHA_EXAME;
Upshot: