• 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
Marshal
Posts: 35279
384
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic