Left outer join in MySQL -
is possible join these 2 tables following result.
table stats
date cus_id pur amount 2015-02-01 2585711 2 100 2015-02-02 2585711 5 250 2015-05-03 2585711 8 400 2015-02-01 2585475 2 100 2015-02-02 2585475 5 250 2015-05-03 2585475 8 400
table customer reg_date cus_id gender country 2014-04-11 2585711 male sweden 2015-02-01 2585475 female sweden
expected result date cus_id pur amount gender country 2014-04-11 2585711 null null male sweden 2015-02-01 2585711 2 100 male sweden 2015-02-02 2585711 5 250 male sweden 2015-05-03 2585711 8 400 male sweden 2015-02-01 2585475 2 100 female sweden 2015-02-02 2585475 5 250 female sweden 2015-05-03 2585475 8 400 female sweden
if use left outer join join 2 tables, following result date cus_id pur amt gender country 2015-02-01 2585711 2 100 male sweden 2015-02-02 2585711 5 250 male sweden 2015-05-03 2585711 8 400 male sweden 2015-02-01 2585475 2 100 female sweden 2015-02-02 2585475 5 250 female sweden 2015-05-03 2585475 8 400 female sweden
my query: select if(a.date null,b.reg_date,a.date) date, b.cus_id, pur, amount, gender, country (select * stats) left outer join (select * customer) b on a.cus_id = b.cus_id
any highly appreciated. thanks!
i don't know if still relevant.
if idea show every date customer active, if didn't make purchase, i'd start table gives me dates , customer pairs first.
select [date],[cust_id] #activity stats union select [reg_date],[cust_id] customer select t1.*, t2.pur, t2.amt #activity t1 left outer join stats t2 on t1.[date] = t2.[date] , t1.[cust_id] = t2.[cust_id]
Comments
Post a Comment