Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Select count(*) with date as condition by using month and year

 
Ummu Hanisah
Greenhorn
Posts: 10
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to display the total number of faculty by using month and year as a date. It return 0 result. I'm using Oracle database.

Here's my sql query

SELECT COUNT(*) FACULTY FROM RESERVATIONS WHERE RESERVEDATE=to_date('NOV-13', 'MM-YY') AND FACULTY='FST' AND STATUS='BOOKED';
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35977
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that only returns a single day - my guess is the first of the month. I can think of two ways to deal with this:

1) Query by a range:


2) Convert your date to a string


The second may perform worse without a function based index. You can check your explain plan to see if the query uses a table scan. If not, this won't be an issue.
 
Ummu Hanisah
Greenhorn
Posts: 10
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Both options work fine. Since I need to pass the date as a parameter, the second approach is what I need.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!