I have below information in table and want to retrive the count if difference between two dates is >= 1.
Id testdate exdate
1 20120502 20120501 --> This should included, because diff is 1
2 20120601 20120601 --> This should not included, because diff is 0
3 20120704 20120703 --> This should included, because diff is 1
4 20120803 20120802 --> This should included, because diff is 1
Based on the above data, my select count should return 3.
I am trying the following, but it’s not giving any results:
select count(to_char(testdate,'YYYYMMDD')-to_char(exdate,'YYYYMMDD')) from test ;
You really should convert those to a
datedata-type though… it saves a lot of problems in the long run.Your query will give you results. It will return 4. It gives you results because as long as the result of
testdate - exdateis not null it will return a value for that row.However, as you’re not using dates Oracle will most probably convert those to numbers, which won’t help for date comparisons should you do that in the future.
Okay, from your comment:
you’re trying something completely different.
Your dates are actually dates; it’s helpful to post this. You’re looking for an analytic function, specifically
count().Note the
truncfunction, which, without additional parameters will remove the time portion of the date this enabling a direct comparison without resorting to converting the date to a character.