行轉列 一條工程資訊多個產品類別為一列顯示

2021-07-03 01:46:53 字數 3428 閱讀 9123

/*統計正在備案工程資訊,

並統計建築鋼材、混凝土、防水卷材、塑料管材、建築外窗、預拌砂漿六類產品類別對應的備案批次與總量,工程面積。

*/--select count(id) beiancishu,sum(r.purchase_num),project_id from bemms.t_purchase_info r group by product_type ,project_id

pro_area 工程面積,

to_char(licence_date, 'yyyy-mm-dd') 發證日期,

project_name 工程名稱,

contractor_name 施工單位,

bemms.fun_get_quality_supervision(quality_supervision) 質量監督機構,

to_char(htkgrq, 'yyyy-mm-dd') 合同開工日期,

to_char(htjgrq, 'yyyy-mm-dd') 合同竣工日期,

to_char(operate_date, 'yyyy-mm-dd') 最後備案時間,

wm_concat(case

when product_type = 1 then

ba_count

end) 建築鋼材備案次數,

wm_concat(case

when product_type = 1 then

ba_sum || '噸'

end) 建築鋼材備案總量,

wm_concat(case

when product_type = 2 then

ba_count

end) 預拌混凝土備案次數,

wm_concat(case

when product_type = 2 then

ba_sum || '立方公尺'

end) 預拌混凝土備案總量,

wm_concat(case

when product_type = 3 then

ba_count

end) 防水卷材備案次數,

wm_concat(case

when product_type = 3 then

ba_sum || '平方公尺'

end) 防水卷材備案總量,

wm_concat(case

when product_type = 4 then

ba_count

end) 防水塗料備案次數,

wm_concat(case

when product_type = 4 then

ba_sum || '千克'

end) 防水塗料備案總量,

wm_concat(case

when product_type = 5 then

ba_count

end) 建築外窗備案次數,

wm_concat(case

when product_type = 5 then

ba_sum || '平方公尺'

end) 建築外窗備案總,

wm_concat(case

when product_type = 7 then

ba_count

end) 塑料管材管件備案次數,

wm_concat(case

when product_type = 7 then

ba_sum || '公尺'

end) 塑料管材管件備案總量,

wm_concat(case

when product_type = 9 then

ba_count

end) 預拌砂漿備案次數,

wm_concat(case

when product_type = 9 then

ba_sum || '噸'

end) 預拌砂漿備案總量

from (select t1.build_licence,

t2.ba_count,

t2.ba_sum,

t2.product_type,

t1.pro_area,

t1.licence_date,

t1.project_name,

t1.contractor_name,

t1.quality_supervision,

t1.htkgrq,

t1.htjgrq,

t1.id,

t1.operate_date

from (select s.build_licence,

s.pro_area,

s.licence_date,

s.project_name,

s.contractor_name,

s.quality_supervision, --質量監督機構

s.htkgrq,

s.htjgrq,

s.id,

case

when p.last_repdata is null then

s.operate_date

else

last_repdata

end operate_date --最後備案時間

from t_sgproject_info s

left join (select project_id, max(operate_date) last_repdata

from t_purchase_info

group by project_id) p

on s.id = p.project_id

where 1 = 1

and sgproject_type = 1

and status in (20, 30)

and symbol = 1

and (s.gclb = '房屋建築工程' or s.gclb is null)) t1,

(select count(id) ba_count,

sum(r.purchase_num) ba_sum,

project_id,

product_type

from bemms.t_purchase_info r

group by product_type, project_id) t2

where t1.id = t2.project_id

order by t1.build_licence, product_type)

group by build_licence,

pro_area,

licence_date,

project_name,

contractor_name,

quality_supervision,

htkgrq,

htjgrq,

operate_date

order by build_licence;

Redis 儲存一條使用者資訊

如果用普通的key value結構來儲存,主要有以下2種儲存方式 第一種方式將使用者id作為查詢key,把其他資訊封裝成乙個物件以序列化的方式儲存,如 set u001 李三,18,20010101 這種方式的缺點是,增加了序列化 反序列化的開銷,並且在需要修改其中一項資訊時,需要把整個物件取回,並...

ORACLE SQL一條語句同時插入多個表

今天在網上看到乙個貼子,用一條語句,將資料同時插入多個表中,覺得很新奇,就自己練了一下,將語句記錄下來 step1 建立三個表,用於實驗測試 create table t table object id number,object name varchar2 128 object type varc...

一條常見的行合併問題 SQL

原來問題 現有兩個表 表一originalword id word 101 about 102 abound 103 beard 104 boast 105 beast 表二similarword id original id similar id 1 101 102 2 102 101 3 103...