Is there an opposite to the "IN" function?

I have this query:

Select Sysdate,Sum(Count(P.Init_Dtime)) From Player p,player_source ps Where Ps.Group_Id In (44,9,42,15,23,73,45,33,69,63,7,49,96,81,28,57,98,74,92,38) And P.Player_Id=Ps.Player_Id and Trunc(p.Init_Dtime) > Trunc(Sysdate) - 7 And Trunc(P.Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd') And Trunc(P.Create_Dtime) < To_Date('2015-sep-9','yyyy-mon-dd') Group By Trunc(P.Init_Dtime) Order By Trunc(P.Init_Dtime) Asc 

I use the "IN" function to include only Group_ID with specific numbers. The Group_ID column can have a value from 1 to 100. How to change this query so that the result includes all Group_Id numbers that are not (44,9,42,15,23,73,45,33,69,63,7,49, 96.81.28.57.98, 74.92.38)?

+4
source share
2 answers

As Peter wrote, using "NOT IN" is the real answer.
The question is why are you using this list as a list ...
I suggested that this list makes some sense and that you may have several lists like this that β€œgroup” some groups together.
If so, you can have another table with these groups and make a join between Ps.Group_Id and this new table ...


Edit:
In another note: If you have indexes on p.Init_Dtime or P.Create_Dtime , Oracle cannot use these indexes because you use these columns inside the function.
You can think about how to work without a function (you can add 2 more columns that will contain truncation values ​​for these columns, index them and use them in the query)


Edit2:
If you need a quick and dirty replacement of a list with information from a table, just remember that you can use select inside the not in part.
If you have a table t1 with col Group_Id and col Valid_Groups , you can do:

 ... Where Ps.Group_Id In (Select Group_Id from T1 where Valid_Groups = 'true') And ... 

The same applies to not in "...

+5
source

You can use NOT to cancel the expression.

So you could say:

 Where Ps.Group_Id NOT IN (44,9 ...) 
+8
source

Source: https://habr.com/ru/post/1433251/


All Articles