/* 1、查询插入示例;2、case when示例。*/insert into t_tempselect user_brand_id, count(case when type = '0' then id end) click_count, count(case when type = '1' then id end) buy_count, count(case when type = '2' then id end) collec_count, count(case when type = '3' then id end) trolley_count,0.0 score from t_user_action2 group by user_brand_idinsert into t_score_brand(brand_id, click_count, buy_count, collect_count, trolley_count)select brand_id, count(case when type = '0' then id end) click_count, count(case when type = '1' then id end) buy_count, count(case when type = '2' then id end) collec_count, count(case when type = '3' then id end) trolley_countfrom t_user_action2 group by brand_idinsert into t_score_brand(brand_id, click_count, click_count_y, click_count_n, buy_count, buy_count_y, buy_count_n, collect_count, collect_count_y, collect_count_n, trolley_count, trolley_count_y, trolley_count_n)select brand_id, sum(click_count) click_count, sum(case when buy_count = 0 then 0 when buy_count <> 0 then click_count end) click_count_y, sum(case when buy_count = 0 then click_count when buy_count <> 0 then 0 end) click_count_n, sum(buy_count) buy_count, sum(case when buy_count = 0 then 0 when buy_count <> 0 then buy_count end) buy_count_y, sum(case when buy_count = 0 then buy_count when buy_count <> 0 then 0 end) buy_count_n, sum(collect_count) collect_count, sum(case when buy_count = 0 then 0 when buy_count <> 0 then collect_count end) collect_count_y, sum(case when buy_count = 0 then collect_count when buy_count <> 0 then 0 end) collect_count_n, sum(trolley_count) trolley_count, sum(case when buy_count = 0 then 0 when buy_count <> 0 then trolley_count end) trolley_count_y, sum(case when buy_count = 0 then trolley_count when buy_count <> 0 then 0 end) trolley_count_n from t_temp group by brand_id