Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 another issue

Author  Topic 

Bill13
Starting Member

2 Posts

Posted - 2009-03-01 : 19:39:59
let supose i have a table OP
columns are
order_id,cust_name,order_date,order_qty,products and my products are
jeans,jacket,shirt,cap

now i wanna write a query to find those customers who have purchased shirt but with shirt they have purchased something else too
like a customer who purchased shirt + jeans
but i dont wanna see shirt in result
select order_id,customer_name,products
from op
where products in ('jeans','jacket','shirt','cap')
and ???????????

how can i remove shirts in results but i wanna see those customers who bought shirts plus some other things
thanx

nr
SQLTeam MVY

12543 Posts

Posted - 2009-03-01 : 20:59:03
select op.order_id,op.customer_name,op.products
from op
join (select distinct order_id from op group by order_id having sum(case when products = 'shirt' then 1 else 0 end) > 0 and count(distinct products) > 1) a
on a.order_id = op.order_id
where products <> 'shirt'



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -