这篇文章将为大家详细讲解有关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查询的结果大致如下。
 

dawei

【声明】:达州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。