June 30, 2004 at 2:03 pm
Hi, Just me again.
I have a customer that wants an SQL query to pull.
CustomerName, StoreVisited when they have visited A Mall and a Boutique. If they only have records reflecting visits to malls I don't care ... if they only have records reflecting visits to Boutiques I don't care ... it is when they go to 1 or more Malls and 1 or more Botitues.
Thanks to Any SQl expert who can help.
July 1, 2004 at 4:31 am
Hi,
You did not leave much to go on schemawise.
Maybe You could do it in the following way:
Retrieve 2 customer sets,
one with all the mall customers, and one with all the boutique customers.
then join these two sets on the primary key of the customertable.
the result is the set of customers that have visited both a mall and a boutique.
below shows the the principle:
select
mc.CustomerName,
mc.StoreVisited
from
customers mc
join customers bc on mc."pk" = bc."pk"
where
mc.StoreType = 'mall'
and bc.StoreType = 'boutique'
gl
/rockmoose
You must unlearn what You have learnt
July 1, 2004 at 8:30 pm
or:
select CustomerId
from customers
group by CustomerID
having
Sum(case when storetype ='Mall' then 1 else o end) > =1
and
Sum(case when storetype ='Boutique' then 1 else o end) > =1
* Noel
July 2, 2004 at 7:51 am
You are a wonderful bunch.
God Bless. Both solutions work great!
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply