Oracle
 sql >> Database >  >> RDS >> Oracle

Mostra le colonne dell'anno corrente e dell'anno precedente in 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;