日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sql item_map

發(fā)布時間:2025/4/5 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sql item_map 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
with /*SELECT 2 as lev, 1.0 as powerunion all select 3,1.9,union all select 4,2.5, ... */ -- lev_info 這段sql 等價于上面,另一種實現(xiàn)而已 lev_info as(SELECT * from UNNEST(ARRAY<STRUCT<lev INT64, power FLOAT64>>[(1, 1), (2, 1.4), (3, 1.9), (4, 2.5), (5, 3.2), (6, 4), (7, 4.9), (8, 5.9), (9, 7), (10, 8.2), (11, 9.5)])), -- 元組的第二個是兵的戰(zhàn)斗力army_info as ( select army_id, freq, -- 這里是對兵的等級進(jìn)行分類,黑道中,最高是11級兵 CASE WHEN army_id < 12050001 then mod(army_id, 100) else DIV((mod(army_id, 100) - 1), 3) + 1 end as lev from( select army_id, count(*) as freq from `mafia1_ods.game_log_army` --提取最近7天的數(shù)據(jù),然后對兵的等級進(jìn)行聚合,統(tǒng)計頻率 where timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY) group by army_id order by freq desc)), army_freq as( --將士兵按照種類進(jìn)行分類相加 select * except(freq), sum(freq) over(partition by merge_id) as freq from(-- 連接字符串 切割字符串 這個mergeid 就是兵的種類 1 是暴徒,二是飛車黨 select army_info.army_id as table_id, CONCAT('army@', SUBSTR(CAST(army_id as STRING), 0, 4)) as merge_id, freq,lev_info.power as exchange_val, 1 as use_log from army_info left join lev_info on army_info.lev = lev_info.lev )),charge_item as( select item_id from `recommend_algorithm.v_mafia1_charge_item`),-- 統(tǒng)計聚合每個table id 在七天之內(nèi)的數(shù)量 item_freq_count as( select table_id as item_id, count(*) as freq from mafia1_ods.game_log_item where timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY) and table_id in (select item_id from charge_item) group by table_id),-- 這張表是和 item_info 相交 item_map as(select t1.*, t2.* except(id) from( select charge_item.item_id, IFNULL(item_freq_count.freq, 0) as freq from charge_item left join item_freq_count on charge_item.item_id = item_freq_count.item_id) as t1 left join (select id, type, type_config, para1, para2, exchange_val from mafia1_dmd.item_info) as t2 on t1.item_id = t2.id),item_freq as( select * except(exchange_val, min_exchange, max_exchange), exchange_val/min_exchange as exchange_val,CAST(max_exchange/min_exchange >= 10 as int64) as use_log from(select * except(freq), sum(freq) over(partition by merge_id) as freq, min(exchange_val) over(partition by merge_id) as min_exchange,max(exchange_val) over(partition by merge_id) as max_exchange,from(--這里的是對字段進(jìn)行合并,個人認(rèn)為這種說法值得商榷select item_id as table_id, CASE WHEN type in (2, 3) then format('item@%d@%d@%s',type, type_config, CASE WHEN type = 2 then CAST(para1 as STRING) else '' end) else format('item@%d', item_id) end as merge_id, freq, CAST(CASE WHEN type in (2, 3) then exchange_val else 1 end as int64) as exchange_val, from item_map)) order by freq desc)select *, DENSE_RANK() over(order by freq desc, merge_id) as map_id from( select * from army_freq union all select table_id, merge_id, exchange_val, use_log, freq from item_freq) order by map_id

總結(jié)

以上是生活随笔為你收集整理的sql item_map的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。