行转列,并在某一列值加基数

SELECT "注册来源",
( case when( "注册来源"='客户端')then
                    "数量"+50+668+549
                      else
                     "数量"
                     end
                    ) AS "数量"
                    FROM
(                    
SELECT
 (case 
                        when( event_property_value='0' )then
                        '客户端'
                     when ( event_property_value='1') then
                         '手机版'
                     when ( event_property_value='2' ) then
                         '管理端添加'
                          when ( event_property_value='3') then
                         '外部用户导入'
                     when ( event_property_value='4') then
                         'CRM新增'
                      when ( event_property_value='5' ) then
                         '主站网页版新增'
                        else
                           '其他'
                      end
                     ) as "注册来源" ,
                     "数量"
FROM
(
SELECT
event_property_value,event_property_code,COUNT( DISTINCT(uid)) AS "数量"
from
(
  SELECT *
  FROM daily_new_clientrpt_master mm left join daily_new_clientrpt_slave ss ON mm.event_id=ss.event_id  WHERE mm.event_code='101101000100016'  AND ss.event_property_code='101101000100016003' AND mm.event_id IN
(SELECT max(event_id) FROM daily_new_clientrpt_master m left join daily_new_clientrpt_slave s ON m.event_id=s.event_id WHERE m.event_code='101101000100016'  AND event_property_code='101101000100016003' GROUP BY uid) 


) GROUP BY event_property_value,event_property_code)) 
 

你可能感兴趣的:(行转列,并在某一列值加基数)