Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Mostrar colunas do ano atual e do ano anterior no oracle

SELECT grade,
       COUNT( DISTINCT CASE WHEN DATE '2015-01-01' >= date_column
                             AND date_column < DATE '2016-01-01'
                            THEN customer_id END
            ) AS number_of_unique_customers_in_2015,
       COUNT( DISTINCT CASE WHEN DATE '2016-01-01' >= date_column
                             AND date_column < DATE '2017-01-01'
                            THEN customer_id END
            ) AS number_of_unique_customers_in_2016
FROM   Customers
WHERE  Date_Column >= DATE '2015-01-01'
AND    Date_Column <  DATE '2017-01-01'
GROUP BY grade;