oracle查询需要在同一个查询中进行比较并得到结果

发布于 2024-10-22 03:21:37 字数 567 浏览 16 评论 0原文

我有一个查询,它从一个数据库中获取记录,然后使用脚本将其插入服务器之间的另一个数据库中。

查询就像:-

select id, date, iscomplete 
from sourcedb.test where id = '1' 
and date = '2011-03-15' and iscomplete = 1;

这个查询返回一些记录,只有当有一定数量的记录时我才需要这些记录。 例如:-“2011-03-15”有 10 条记录,那么我只想在所有 10 条记录的完成度为 1 时才获取这 10 条记录。

我不想对其进行硬编码,因为记录在不久的将来可能会从 10 条增加到 20 条。

有什么方法可以修改我的原始查询并检查当天所有记录是否 iscomplete = 1,然后获取记录,否则不返回任何内容。

我需要为此查询添加一个条件,即如果有 10 条记录,其中一半已完成,即 isComplete = 1,其中一半为 isComplete <>; 1 在这种情况下,我不希望查询有任何输出,除非所有记录都有 isComplete = 1。

问候, 玛纳西

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 the 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2024-10-29 03:21:37

只需进行下一次检查

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文