oracle query need to compare and get result in the same query
I have a query which fetch record from one db and insert it into another db across servers using script.
the query is like :-
select id, date, iscomplete
from sourcedb.test where id = '1'
and date = '2011-03-15' and iscomplete = 1;
this query returns me some records, which i want only when there are certain number of records. for ex:- there are 10 records for '2011-03-15' then I want to fetch those 10 records only when is complete is 1 for all th开发者_C百科e 10 records.
I dont want to hardcode it as records can increase in near future from 10 to 20.
Is there any way I can modify my original query and check if iscomplete = 1 for all the records for that day then fetch the records else return nothing.
I need to add one more condition to this query that is if there are 10 records and half of them are completed i.e. isComplete = 1 and half of them are isComplete <> 1 in this case I dont want any output from the query untill and unless all the record has isComplete = 1.
Regards, Manasi
Just make the next check
select id, date, iscomplete
from sourcedb.test
where id = '1'
and date = '2011-03-15'
and not exists (select 1 from sourcedb.test where id = '1'
and date = '2011-03-15' and isComplete <> 1);
精彩评论