简体   繁体   English

当我在 Snowflake 中运行我的查询时,它会继续运行,但如果没有 OR 语句,它会在几秒钟内运行

[英]When I run my query in Snowflake it keeps running but without the OR statement is runs in merely seconds

I have a query where I select 3 columns from two tables.我有一个查询,其中我 select 来自两个表的 3 列。 First I check if a clientnumber is in the list, for which I used a "IN" statement.首先,我检查客户编号是否在列表中,为此我使用了“IN”语句。 Then I check if a clientnumber is also in another table so that both numbers are equal.然后我检查 clientnumber 是否也在另一个表中,以便两个数字相等。

At last I want to exclude values that are ending on a certain value.最后我想排除以某个值结尾的值。 And this is where it goes wrong.这就是问题所在。

When I have just a single "NOT LIKE" it runs perfectly fine but when I use a "OR NOT LIKE" after that it keeps on running.当我只有一个“NOT LIKE”时,它运行得很好,但是当我使用“OR NOT LIKE”之后它继续运行。

See my query below:请参阅下面的查询:

SELECT "MAIL_ADDR", "ClientNumber", "CNumber" 
FROM "ADRESSES", CUSTOMERS
WHERE "ClientNumber" IN ('0000206302','0000206307','0000206309','0000206321'                                        
    AND "ClientNumber" = "CNumber"
    AND "MAIL_ADDR" NOT LIKE '%domain.nl' 
    OR "MAIL_ADDR" NOT LIKE '%domain.com'

I don't know what to change in my query as I don't get any error messages from Snowflake.我不知道要在我的查询中更改什么,因为我没有从 Snowflake 收到任何错误消息。 Maybe it has something to do with performance issues.也许它与性能问题有关。

The query could be rewritten to use JOIN syntax and condition for exclusion should be connected with AND :可以重写查询以使用 JOIN 语法,排除条件应与AND连接:

SELECT "MAIL_ADDR", "ClientNumber", "CNumber" 
FROM "ADRESSES"
JOIN CUSTOMERS
  ON "ClientNumber" = "CNumber"
WHERE "ClientNumber" IN ('0000206302','0000206307','0000206309','0000206321')
    AND "MAIL_ADDR" NOT LIKE '%domain.nl' 
    AND "MAIL_ADDR" NOT LIKE '%domain.com';

A more compact way is to use NOT LIKE ANY syntax:一种更紧凑的方法是使用NOT LIKE ANY语法:

SELECT "MAIL_ADDR", "ClientNumber", "CNumber" 
FROM "ADRESSES"
JOIN CUSTOMERS
  ON "ClientNumber" = "CNumber"
WHERE "ClientNumber" IN ('0000206302','0000206307','0000206309','0000206321')       
 AND NOT ("MAIL_ADDR" LIKE ANY ('%domain.nl', '%domain.com'));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Select查询返回的DATE在SQL中没有TIME,但是当我运行ASP项目时,它不断添加“ 12:00:00 AM” - SQL Select Query returning DATE without TIME inside SQL but i when i run my ASP project it keeps adding “12:00:00 AM” 此查询在Access 2010中运行完美,但当我尝试在我的代码中执行它时,我在INSERT INTO语句中出现语法错误 - This query runs perfectly in Access 2010 but when I try to execute it in my code I get Syntax error in INSERT INTO statement 为什么在查询中添加WHERE语句(在具有索引的列上)会使我的运行时间从几秒钟增加到几分钟? - Why does adding a WHERE statement (on a column with an index) to my query increase my run time from seconds to minutes? 如何优化这个在 ORACLE 中运行大约 4 秒的 SQL 语句?我想查询和使用更少的时间 - How to optimize this SQL statement that run about 4 seconds in ORACLE?I want to query and use less time 为什么当我在雪花中运行时会出错? - Why this gives an error when I run in snowflake? 雪花 SQL 语句 Pivot 不适用于我正在使用的查询 - Snowflake SQL Statement Pivot will not work with query I am using 在Oracle SQL Developer中运行的SQL查询但是当我从我的JAVA程序运行查询时,它给出了Sql异常 - Sql Query running in oracle SQL Developer But when i run the query from my JAVA program it is giving Sql exception SQL Server,Lazy Spool 在 View 中无休止地运行,但当我直接运行查询时却没有 - SQL Server, Lazy Spool runs endlessly in View but not when I run the query directly 如何在不运行实际查询的情况下检查JDBC语句的SQL语法? - How can I check SQL syntax for a JDBC statement without running the actual query? 为什么使用“in”和“on”语句的查询会无限运行 - Why query with “in” and “on” statement runs infinitely
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM