共計 3019 個字符,預(yù)計需要花費 8 分鐘才能閱讀完成。
這篇文章將為大家詳細講解有關(guān) Excel 中怎么實現(xiàn)動態(tài)行轉(zhuǎn)列,文章內(nèi)容質(zhì)量較高,因此丸趣 TV 小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
查詢的 SQL 如下
ol start= 1 >
select type,ts,cn,as DECIMAL) val from (
select
starttime, 發(fā)布 type,base.ts,base.cn,ifnull(t1.val,0) val
from
(
select
t1.*,
startdate+ interval id-1 hour starttime,
startdate+ interval id hour endtime,
date_format(startdate+ interval id-1 hour, %m%d%H) ts,
vars.*
from nums ,(select ${starttime} startdate,${endtime} enddate) vars,
(
select mvbox_user.user_otherinfo busidatatype,1 type, 內(nèi)容審核. 個人資料 cn union all
select mvbox_user.user_baseinfo ,1, 內(nèi)容審核. 個人喜好 union all
select photo_album ,1, 內(nèi)容審核. 相冊信息 union all
select photo_list ,1, 內(nèi)容審核. 圖片信息 union all
select music_original ,1, 內(nèi)容審核. 原唱信息 union all
select music_cover ,1, 內(nèi)容審核. 翻唱信息 union all
select music_accompany ,1, 內(nèi)容審核. 伴奏信息 union all
select music_album ,1, 內(nèi)容審核. 音樂專輯 union all
select music_video ,1, 內(nèi)容審核. 視頻信息 union all
select blog_album ,1, 內(nèi)容審核. 日志與文章 union all
select mvbox_user.user_baseinfo ,2, 內(nèi)容審核.MVBOX 頭像審核
) t1
where id = TIMESTAMPDIFF(hour,startdate,enddate)
order by busidatatype,type,starttime
) base join
(
select busidatatype,type,date_format(createtime, %m%d%H) ts,from audit_obj_detail
where createtime =${starttime} and createtime ${endtime}
and busitype = mvbox
group by busidatatype,type,date_format(createtime, %m%d%H)
) t1 on (base.busidatatype=t1.busidatatype and base.type=t1.type and base.ts=t1.ts)
group by base.busidatatype,base.type,base.ts,base.cn
union all
select
starttime, 審核 type,base.ts,base.cn,ifnull(t1.val,0) val
from
(
select
t1.*,
startdate+ interval id-1 hour starttime,
startdate+ interval id hour endtime,
date_format(startdate+ interval id-1 hour, %m%d%H) ts,
vars.*
from nums ,(select ${starttime} startdate,${endtime} enddate) vars,
(
select mvbox_user.user_otherinfo busidatatype,1 type, 內(nèi)容審核. 個人資料 cn union all
select mvbox_user.user_baseinfo ,1, 內(nèi)容審核. 個人喜好 union all
select photo_album ,1, 內(nèi)容審核. 相冊信息 union all
select photo_list ,1, 內(nèi)容審核. 圖片信息 union all
select music_original ,1, 內(nèi)容審核. 原唱信息 union all
select music_cover ,1, 內(nèi)容審核. 翻唱信息 union all
select music_accompany ,1, 內(nèi)容審核. 伴奏信息 union all
select music_album ,1, 內(nèi)容審核. 音樂專輯 union all
select music_video ,1, 內(nèi)容審核. 視頻信息 union all
select blog_album ,1, 內(nèi)容審核. 日志與文章 union all
select mvbox_user.user_baseinfo ,2, 內(nèi)容審核.MVBOX 頭像審核
) t1
where id = TIMESTAMPDIFF(hour,startdate,enddate)
order by busidatatype,type,starttime
) base join
(
select busidatatype,type,date_format(AuditTime, %m%d%H) ts,from audit_obj_detail
where AuditTime =${starttime} and AuditTime ${endtime}
and busitype = mvbox
group by busidatatype,type,date_format(AuditTime, %m%d%H)
) t1 on (base.busidatatype=t1.busidatatype and base.type=t1.type and base.ts=t1.ts)
group by base.busidatatype,base.type,base.ts,base.cn
) t1 ;
由于這個 SQL 已然比較復(fù)雜,再加動態(tài)行轉(zhuǎn)列, 可讀性幾乎就沒有了.
這個 SQL 查詢的結(jié)果大致如下。
其中 type 可能是發(fā)布或者審核.
ts 表示月 日 和小時
cn 表示模塊類型
val 表示數(shù)量.
將這個結(jié)果導(dǎo)入至 Excel
選擇插入, 數(shù)據(jù)透視表
然后將 ts 設(shè)置為列標簽, 這樣 ts 就由行變成列顯示
cn 和 type 作為行標簽.
val 作為顯示數(shù)值
然后選擇視圖 - 凍結(jié)窗格 - 凍結(jié)首列 方便觀看數(shù)據(jù)
可以看到如下結(jié)果
完全符合動態(tài)行轉(zhuǎn)列的需求, 并且可以排序和篩選. 太強大了.
關(guān)于 Excel 中怎么實現(xiàn)動態(tài)行轉(zhuǎn)列就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。