help with writing a sub query and assigning results to trigger a true or false result
Need some help on this query. So far I have it returning a count based on data from couple days previous.
What I am ultimately trying to do now is create a query that basically tells me if the count(*)=Xn value, then query is valid else no data set.
Its ok if I get no results.
Here's my query:
SQL> select count(*) from in_source where to_date(year||'/'||month||'/'||day, 'YYYY/MM/DD') >= trunc(sysdate) - 1;
COUNT(*)
----------
500
So, basically if count(*)=500 then this query开发者_StackOverflow中文版 is 1 (false) or 0 (no results). I'm thinking this would require a sub query?
Can someone help me tweak this? Thank you.
Don't really understand what you are after, but hopefully one of these will work..
If you are trying to get if count(*) = 500 return a 1 else return a 0 then try this:
select case when count(*) = 500 then 1 else 0 end result
from in_source
where to_date(year||'/'||month||'/'||day, 'YYYY/MM/DD') >= trunc(sysdate) - 1;
If you are trying to get if count(*) = 500 then return a 1 else don't return any rows try this:
select 1 result
from in_source
where to_date(year||'/'||month||'/'||day, 'YYYY/MM/DD') >= trunc(sysdate) - 1
having count(*) = 500;
Not sure if this is what you are looking for, but I give it a try:
select 1 from dual
where 500=(select count(*) from in_source
where to_date(year||'/'||month||'/'||day, 'YYYY/MM/DD') >= trunc(sysdate) - 1);
精彩评论