Re: Newbie: Sub-query help
Full joins are less awkward for problems like this. And in MySQL, full joins usually optimise better than In(Select...) semi-joins, by a wide margin in MySQL 5.0 and 5.1, less so in 5.5.
Is this what you mean?
select
o.state_cd,
o.customer_id,
sum(o.premium_item_orderd) as premium_item_orderd ,
count(o.order_id) as orders
from order_mart_v as o
join (
select customer_id
from order_mart_v
where year(order_dt)=2015 and month(order_dt)=5 and online_indicator=1 and telmkt_ind=0
group by customer_id
having( count(*) >= 2 ) -- restrict to 2+ may orders
) as may2015
group by o.state_cd, o.customer_id;
(Your combination of ansi quotes, redundant database and table references, no aliases, and pervasive upper case, makes reading your query quite a challenge.)
Subject
Written By
Posted
Re: Newbie: Sub-query help
June 24, 2015 10:43PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.