sql >> Base de Datos >  >> RDS >> PostgreSQL

Devolver valores individuales nulos con postgres tablefunc crosstab()

Use la segunda forma de la función :

Por ejemplo:

SELECT *
FROM crosstab(
    $$
        SELECT lab_tests_results.batch_id, lab_tests.test_name, lab_tests_results.test_result::FLOAT
        FROM lab_tests_results, lab_tests
        WHERE lab_tests.id=lab_tests_results.lab_test 
        AND (
            lab_tests.test_name LIKE 'Test Name 1' 
            OR lab_tests.test_name LIKE 'Test Name 2')
        ORDER BY 1,2
    $$,
    $$ 
        VALUES('pH'), ('Temp') 
    $$
) AS final_result(batch_id VARCHAR, "pH" FLOAT, "Temp" FLOAT);