Jump to content

SQL Experts come here


ranjith23

Recommended Posts

Input SQL:

 

Select * from data a where a.id = ‘1944’ 

And (case when a.country = ‘USA’ then ‘1=1’

Else ‘Exists(Select * from skip_id b where a.id = b.id)’ end);

 

Expected Output SQL:

 

USA: 

Select * from data a where a.id = ‘1944’ 

And 1 = 1; 

 

Non USA:

Select * from data a where a.id = ‘1944’ 

And Exists(Select * from skip_id b where a.id = b.id);

 

Notes: needed to be fixed by modifying case logic only. No other option

 

Link to comment
Share on other sites

Select * from data a where a.id = '1944' 
And  (( a.country = 'USA' AND  1=1 ) OR  (a.id =(Select b.id from skip_id b where a.id = b.id) ))

Link to comment
Share on other sites

1 hour ago, RamGopalVarma said:

Select * from data a where a.id = '1944' 
And  (( a.country = 'USA' AND  1=1 ) OR  (a.id =(Select b.id from skip_id b where a.id = b.id) ))

velli @Herpes treatment teesko mundu

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...