I want to take into account all records even with NULL values when calculating the count for num_zaprosa and num_otveta, but not show them in the result set.
Is it possible to do this?
here is my code, but it did not help me solve my problem:
WITH counted_records AS (
SELECT num_zaprosa, num_otveta,
COUNT(*) AS count_all_records,
SUM(CASE WHEN num_zaprosa IS NOT NULL THEN 1 ELSE 0 END) AS count_num_zaprosa,
SUM(CASE WHEN num_otveta IS NOT NULL THEN 1 ELSE 0 END) AS count_num_otveta
FROM your_table
GROUP BY num_zaprosa, num_otveta
)
SELECT num_zaprosa, num_otveta, count_all_records, count_num_zaprosa, count_num_otveta
FROM counted_records
WHERE num_zaprosa IS NOT NULL OR num_otveta IS NOT NULL;