Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Boolean algebra in some Rows tutorial by Aketi Jyuuzou

Aketi Jyuuzou
Member Posts: 1,072 Bronze Badge
This thread explains Boolean algebra in some Rows B-)
*****************************************************************
1. What is Boolean algebra ? ?:|
http://en.wikipedia.org/wiki/Elementary_Boolean_algebra
*****************************************************************
2. What is usage of "Boolean algebra in some Rows" ? ?:|
It is very effective when we want to check wheather some Rows meet conditions or not.
**************************
For exsample1
*****************************************************************
1. What is Boolean algebra ? ?:|
http://en.wikipedia.org/wiki/Elementary_Boolean_algebra
*****************************************************************
2. What is usage of "Boolean algebra in some Rows" ? ?:|
It is very effective when we want to check wheather some Rows meet conditions or not.
**************************
For exsample1
create table boolEx1(ID,Val) as select 1,'aaa' from dual union all select 1,'bbb' from dual union all select 1,'ccc' from dual union all select 2,'aaa' from dual union all select 2,'aaa' from dual union all select 2,'ccc' from dual union all select 3,'aaa' from dual union all select 3,'bbb' from dual union all select 4,'eee' from dual; chk1 I will check each ID has nothing either 'aaa' or 'ccc'. chk2 I will check each ID has at least 'aaa' or 'ccc'. chk3 I will check each ID has both 'aaa' and 'ccc'. chk4 I will check each ID has something other than 'aaa' or 'ccc'. chk5 I will check each ID has at least least 'aaa' or 'ccc'. select ID,Val, min(case when Val in('aaa','ccc') then 1 else 0 end) over(partition by ID) as chk1, max(case when Val in('aaa','ccc') then 1 else 0 end) over(partition by ID) as chk2, max(case when Val='aaa' then 1 else 0 end) over(partition by ID) *max(case when Val='ccc' then 1 else 0 end) over(partition by ID) as chk3, min(case when Val in('aaa','ccc') then 0 else 1 end) over(partition by ID) as chk4, max(case when Val in('aaa','ccc') then 1 else 0 end) over(partition by ID) as chk5 from boolEx1 order by ID,Val; ID VAL CHK1 CHK2 CHK3 CHK4 CHK5 -- --- ---- ---- ---- ---- ---- 1 aaa 0 1 1 0 1 1 bbb 0 1 1 0 1 1 ccc 0 1 1 0 1 2 aaa 1 1 1 0 1 2 aaa 1 1 1 0 1 2 ccc 1 1 1 0 1 3 aaa 0 1 0 0 1 3 bbb 0 1 0 0 1 4 eee 0 0 0 1 0
Comments
-
**************************
For exsample2
Of course.We can use above logic in select with group by and havingselect ID, min(case when Val in('aaa','ccc') then 1 else 0 end) as chk1, max(case when Val in('aaa','ccc') then 1 else 0 end) as chk2, max(case when Val='aaa' then 1 else 0 end) *max(case when Val='ccc' then 1 else 0 end) as chk3, min(case when Val in('aaa','ccc') then 0 else 1 end) as chk4, max(case when Val in('aaa','ccc') then 1 else 0 end) as chk5 from boolEx1 group by ID order by ID; ID CHK1 CHK2 CHK3 CHK4 CHK5 -- ---- ---- ---- ---- ---- 1 0 1 1 0 1 2 1 1 1 0 1 3 0 1 0 0 1 4 0 0 0 1 0
*****************************************************************
3. What is summary of "Boolean algebra in some Rows" ? ?:|
I have used this Logic.
http://en.wikipedia.org/wiki/First-order_logic"max(case when P(X) then 1 else 0 end) = 1" is for some X:P(X) "min(case when P(X) then 1 else 0 end) = 1" is for all X:P(X) "max(case when P(X) then 0 else 1 end) = 1" is for some X:not(P(X)) "min(case when P(X) then 0 else 1 end) = 1" is for all X:not(P(X))
and sometimes I use below one."max(case when P(X) then 1 else 0 end) * max(case when Q(X) then 1 else 0 end) = 1" is for some X:P(X) and for some X:Q(X)
*****************************************************************
4. What threads are using "Boolean algebra in some Rows" ?:|
I will write that threads sorted by easy.
634915
551061
526715
557138
551338
585154
621506
*****************************************************************
OracleSQLPuzzle (MyHomePage)
http://www.geocities.jp/oraclesqlpuzzle
sister thread
Tabibitosan method tutorial 1007478 -
These forums are generally not used to post tutorials so it is likely those that might benefit from them won't find what you've posted.
Consider helping us kick off the new Sample Code section:
https://www.samplecode.oracle.com -
I assume in your Boolean Algebra 0 represents False and 1 represents True. If so:chk1 I will check each ID has only both 'aaa' and 'ccc'min(case when Val in('aaa','ccc') then 1 else 0 end) over(partition by ID) as chk1You mean chk1 will check if each ID has nothing but either 'aaa'or 'ccc'chk3 I will check each ID has both 'aaa' and 'ccc'.max(case when Val='aaa' then 1 else 0 end) over(partition by ID) * max(case when Val='bbb' then 1 else 0 end) over(partition by ID) as chk3I assume it is typo and you meant 'ccc' not 'bbb'.chk4 I will check each ID does not have only both 'aaa' and 'ccc'.min(case when Val in('aaa','ccc') then 0 else 1 end) over(partition by ID) as chk4You mean chk4 will check if each ID has something other than 'aaa' or 'ccc'. It might not have 'aaa' or 'ccc' at all.chk5 I will check each ID does not have at least 'aaa' or 'ccc'.max(case when Val in('aaa','ccc') then 1 else 0 end) over(partition by ID) as chk5You mean chk5 will check each ID has at least 'aaa' or 'ccc'.
SY. -
In chk3 you made a typo as Solomon has already write.chk1 I will check each ID has only both 'aaa' and 'ccc'.So I think chk4=¬chk1 (NOT chk1). If so you should use max instead of min.
chk4 I will check each ID does not have only both 'aaa' and 'ccc'.chk2 I will check each ID has at least 'aaa' or 'ccc'.So I think chk5=¬chk2 (NOT chk2). If so you should use min instead of max.
chk5 I will check each ID does not have at least 'aaa' or 'ccc'.SQL> select ID, 2 min(case when Val in('aaa','ccc') then 1 else 0 end) as chk1, 3 max(case when Val in('aaa','ccc') then 1 else 0 end) as chk2, 4 max(case when Val='aaa' then 1 else 0 end)*max(case when Val='ccc' then 1 else 0 end) as chk3, 5 max(case when Val in('aaa','ccc') then 0 else 1 end) as chk4, 6 min(case when Val in('aaa','ccc') then 0 else 1 end) as chk5 7 from boolEx1 8 group by ID 9 order by id; ID CHK1 CHK2 CHK3 CHK4 CHK5 ---------- ---------- ---------- ---------- ---------- ---------- 1 0 1 1 1 0 2 1 1 1 0 0 3 0 1 0 1 0 4 0 0 0 1 1
Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/26/leggiamo-meglio-il-dizionario-dati-utilizzando-dbms_metadata/] -
OOPS my English is not good at.
I have fixed my English miss of previous post.
When I will answer similar threads,I will write these tutorial threads URL B-)
This discussion has been closed.