I am very new when it comes to using SQL and what I am attempting to do is select the waterUsage and electrcityUsage using only the month and year and select the waterUsage and
One option uses TO_CHAR
:
select electrcityUsage, waterUsage
from monthlyBill
where accountNumber = '211' and
to_char(billing_date, 'MM-YYYY') = '12-2012'
This assumes that you're actually using Oracle, and not SQL Server.
If you wanted 2012
and 2011
then just go ahead and add another condition to the WHERE
clause. I might use EXTRACT
in this case:
select electrcityUsage, waterUsage
from monthlyBill
where accountNumber = '211' and
extract(month from billingDate) = 12 and
extract(year from billingdate) in (2011, 2012)