sql - how to select specific rows with values with \ without group by -


cust_id | acc_type --------------------    1     |   l1 --------------------    1     |   m1 --------------------    1     |   o1 --------------------    2     |   r1 --------------------    3     |   s1 -------------------- 

result needed is

 cust_id | acc_type --------------------    1     |   l1 --------------------    1     |   m1 -------------------- 

i.e single cust_id need these 2 values. when use group 3 mapped 1. please me resolve in db2\sql

based on comment, seem want:

select t.* t (t.acc_type = 'l1' ,        exists (select 1 t t2 t2.cust_id = t.cust_id , t2.acc_type = 'm1')       ) or       (t.acc_type = 'm1' ,        exists (select 1 t t2 t2.cust_id = t.cust_id , t2.acc_type = 'l1')       ) ; 

for query, want index on t(cust_id, acc_type).


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -