mysql程序语句范文,SQL语句(MySQL)
/*?1、查詢插入示例;2、case?when示例。*/
insert?into?t_temp
select?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_id
insert?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_count
from?t_user_action2?group?by?brand_id
insert?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
總結
以上是生活随笔為你收集整理的mysql程序语句范文,SQL语句(MySQL)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: phpstorm支持php7吗,PHPS
- 下一篇: 求一个搞笑qq网名。