標籤:instr 儲存 miss char sql join order by 登入 bsp
這個馬甲屬於一個表,appStore另一張表,使用者登入表,主要操作的就是這三個表。
我這裡的馬甲和app的id都與使用者登入表中的channel對應,在channel存放的是majiaId + “|” + storeId
第一版sql:
select count(*), sms_tag_name, store_name from (select id, create_date, SUBSTR(channel,0,NVL(INSTR(channel, ‘|‘, 1,1),0)-1) sms_tag_id, SUBSTR(channel,NVL(INSTR(channel, ‘|‘, 1,1),0)+1, length(channel)- NVL(INSTR(channel, ‘|‘, 1,1),0)) store_id, channel from user_login where NVL(INSTR(channel, ‘|‘, 1,1),0) != 0) u INNER JOIN majia_sms_tag mst ON mst.sms_tag_id = u.sms_tag_id INNER JOIN app_store aps ON aps.store_id = u.store_id where store_name=‘華為‘ group by sms_tag_name, store_name
發現存在問題,針對使用者登入中農沒有儲存到的馬甲和市集的註冊量找不出來等,資訊不全面
第二版:
select count(u.id), sms_tag_name, store_namefrom ( select sms_tag_id, sms_tag_name, store_id, store_name, concat(concat(sms_tag_id,‘|‘),store_id) as channel from majia_sms_tag cross join app_store ) ma left join ( select * from user_login where to_char(create_date, ‘YYYYMMDDHH24MISS‘) >= ‘20160801000000‘ and to_char(create_date, ‘YYYYMMDDHH24MISS‘) <= ‘20170801000000‘ ) u on u.channel = ma.channelwhere sms_tag_id=‘com.rybring.weilidai‘ and store_id=‘platf.360‘ group by sms_tag_name,store_nameorder by sms_tag_name,store_name
還是用了cross join,第一次用到擦,並且將兩個查詢的條件分別放在子查詢中和外面。神來之筆。
以後再有類似需求可以參考。
根據馬甲、市集、統計每天的註冊量,要求可以根據選擇馬甲和app,馬甲和appstrore和user_login不同表問題