Oracle
 sql >> Base de données >  >> RDS >> Oracle

Afficher les colonnes de l'année en cours et de l'année précédente dans 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;