SELECT
substr(purchase_time, 1,7) AS mon,
CASE
WHEN product_type = 'iPhone' THEN 'iPhone'
ELSE 'Not iPhone'
END AS category,
COUNT(DISTINCT user_id) AS user_count
FROM apple_pchs_rcd
GROUP BY mon, category
ORDER BY mon, category;
select t1.cust_uid,t2.cust_uid from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.cust_uid!=t2.cust_uid and t1.mch_nm=t2.mch_nm
where t1.cust_uid='mt10000' and t1.mch_nm in ('庄家界(千灯店)','黄记烘培宫廷桃酥王')
group by t1.cust_uid,t2.cust_uid order by t2.cust_uid
select t1.cust_uid,t2.cust_uid from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.cust_uid=t2.cust_uid and t1.mch_nm=t2.mch_nm
where t1.cust_uid='mt10000' and t2.mch_nm in ('庄家界(千灯店)','黄记烘培宫廷桃酥王')
group by t1.cust_uid,t2.cust_uid order by t2.cust_uid
select t1.cust_uid,t2.cust_uid from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.cust_uid=t2.cust_uid and t1.mch_nm=t2.mch_nm
where t1.cust_uid='mt10000' and t2.mch_nm in ('庄家界(千灯店)','黄记烘培宫廷桃酥王')
select
t1.cust_uid,
t2.cust_uid,
t1.mch_nm
from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.mch_nm=t2.mch_nm and t1.cust_uid!=t2.cust_uid
where t1.mch_nm='兰州李晓明拉面馆' and t1.cust_uid='MT10000'
group byt1.cust_uid,
t2.cust_uid,
t1.mch_nm
order by t1.cust_uid,t2.cust_uid
select
t1.cust_uid,
t2.cust_uid,
t1.mch_nm
from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.mch_nm=t2.mch_nm and t1.cust_uid!=t2.cust_uid
where t1.mch_nm='兰州李晓明拉面馆' and t2.mch_nm='兰州李晓明拉面馆'
group byt1.cust_uid,
t2.cust_uid,
t1.mch_nm
order by t1.cust_uid,t2.cust_uid
select
t1.cust_uid,
t2.cust_uid,
t1.mch_nm
from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.mch_nm=t2.mch_nm and t1.cust_uid!=t2.cust_uid
where t1.mch_nm='兰州李晓明拉面馆'
group byt1.cust_uid,
t2.cust_uid,
t1.mch_nm
order by t1.cust_uid,t2.cust_uid
select
t1.cust_uid,
t2.cust_uid,
t1.mch_nm
from mt_trx_rcd1 t1
left join mt_trx_rcd1 t2 on t1.mch_nm=t2.mch_nm and t1.cust_uid!=t2.cust_uid
where t1.mch_nm='兰州李晓明拉面馆'
order by t1.cust_uid,t2.cust_uid