![]() ![]() When a row is returned for the month of February or March a null is returned in the January column.Why do you get null values for January 2020 and March 2021? That’s because the query returns null values when the conditions in the SELECT-list aren’t met for a row return. It produces the following correct results (at least in response to the query above): GROUP BY EXTRACT(YEAR FROM transaction_date) WHEN EXTRACT(MONTH FROM transaction_date) IN (1,2,3) THEN transaction_amount WHEN EXTRACT(MONTH FROM transaction_date) = 3 THEN transaction_amount WHEN EXTRACT(MONTH FROM transaction_date) = 2 THEN transaction_amount WHEN EXTRACT(MONTH FROM transaction_date) = 1 THEN transaction_amount SELECT EXTRACT(YEAR FROM transaction_date) AS "Year" SELECT EXTRACT ( YEAR FROM transaction_date ) AS "Year", SUM ( CASE WHEN EXTRACT ( MONTH FROM transaction_date ) = 1 THEN transaction_amountĮND ) AS "Jan", SUM ( CASE WHEN EXTRACT ( MONTH FROM transaction_date ) = 2 THEN transaction_amountĮND ) AS "Feb", SUM ( CASE WHEN EXTRACT ( MONTH FROM transaction_date ) = 3 THEN transaction_amountĮND ) AS "Mar", SUM ( CASE WHEN EXTRACT ( MONTH FROM transaction_date ) IN ( 1, 2, 3 ) THEN transaction_amountĮND ) AS "1FQ" FROM transaction WHERE transaction_date BETWEEN '' AND '' GROUP BY EXTRACT ( YEAR FROM transaction_date ) ORDER BY 1 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |