加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Excel中怎么做好动态行转列

发布时间:2022-01-21 03:15:32 所属栏目:MySql教程 来源:互联网
导读:这篇文章将为大家详细讲解有关Excel中怎么实现动态行转列,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。 查询的SQL如下 ol start=1 class=dp-sql white-space:normal; select type,ts,cn,as DECIMAL)
      这篇文章将为大家详细讲解有关Excel中怎么实现动态行转列,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
  
      查询的SQL如下
<ol start="1" class="dp-sql" white-space:normal;">
 
select type,ts,cn,as DECIMAL) val from (  
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,'内容审核.个人资料' cn union all   
        select 'mvbox_user.user_baseinfo',1,'内容审核.个人喜好' union all   
        select 'photo_album',1,'内容审核.相册信息' union all   
        select 'photo_list',1,'内容审核.图片信息' union all   
        select 'music_original',1,'内容审核.原唱信息' union all   
        select 'music_cover',1,'内容审核.翻唱信息' union all   
        select 'music_accompany',1,'内容审核.伴奏信息' union all   
        select 'music_album',1,'内容审核.音乐专辑' union all   
        select 'music_video',1,'内容审核.视频信息' union all   
        select 'blog_album',1,'内容审核.日志与文章' union all   
        select 'mvbox_user.user_baseinfo',2,'内容审核.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,'内容审核.个人资料' cn union all   
        select 'mvbox_user.user_baseinfo',1,'内容审核.个人喜好' union all   
        select 'photo_album',1,'内容审核.相册信息' union all   
        select 'photo_list',1,'内容审核.图片信息' union all   
        select 'music_original',1,'内容审核.原唱信息' union all   
        select 'music_cover',1,'内容审核.翻唱信息' union all   
        select 'music_accompany',1,'内容审核.伴奏信息' union all   
        select 'music_album',1,'内容审核.音乐专辑' union all   
        select 'music_video',1,'内容审核.视频信息' union all   
        select 'blog_album',1,'内容审核.日志与文章' union all   
        select 'mvbox_user.user_baseinfo',2,'内容审核.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已然比较复杂,再加动态行转列,可读性几乎就没有了.
 
这个SQL查询的结果大致如下。
 

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读