• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Getting additional e_id even after joining conditions are satisfied in SELECT query

Resolved: Getting additional e_id even after joining conditions are satisfied in SELECT query

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Database version: Oracle 18c.
I want to create one report wherein I need to include only those e_id whose ref_id is not null and sys_other is either Email or null. Other than this combination, that e_id will not be considered in the report. For ex:
e_id = 122 it should come in report as ref_id is not null and sys_other is null
e_id = 6122 it should not come in report as ref_id is null
e_id = 805 it should also not come in report where ref_id is not null but in sys_other we have value other than Email and null which is Test so we should exclude this e_id
Logic: Basically, need to check two columns ref_id and sys_other. If ref_id is null then we should exclude those e_id and if it is not null then need to check sys_other column and if it has ‘Email’ than include otherwise exclude irrespective of column sys_name
My Attempt:
But the above query is giving me 805 id which should be excluded.
Expected output:

Answer:

You can try:
Which will group by each e_id and for each group:
  • count the non-null ref_id and ensure that there is as least 1 row and
  • count the non-null sya_other values that are not Email and ensure that there are no rows that are non-null, non-email rows in the group.

If you have better answer, please add a comment about this, thank you!

oracle sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why is NGINX’s $request_uri empty?

24/03/2023

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.