sql >> Base de Datos >  >> RDS >> Oracle

Trabajar con fechas en Oracle SQL

Una opción usa TO_CHAR :

select electrcityUsage, waterUsage 
from monthlyBill
where accountNumber = '211' and
     to_char(billing_date, 'MM-YYYY') = '12-2012'

Esto supone que en realidad está utilizando Oracle y no SQL Server.

Si quisieras 2012 y 2011 luego siga adelante y agregue otra condición a WHERE cláusula. Podría usar EXTRACT en este caso:

select electrcityUsage, waterUsage 
from monthlyBill
where accountNumber = '211' and
    extract(month from billingDate) = 12 and
    extract(year from billingdate) in (2011, 2012)