Mysql
 sql >> Database >  >> RDS >> Mysql

mysql pivoting:come posso recuperare i dati dalla stessa tabella in colonne diverse?

puoi provare questo

SELECT ( CASE WHEN ps_month = '04' THEN ps_target_ecpm
              ELSE 0
         END ) AS april_target_ecmp
       ,( CASE WHEN ps_month = '04' THEN ps_actual_ecpm
               ELSE 0
          END ) AS april_actual_ecpm
       ,( CASE WHEN ps_month = '03' THEN ps_target_ecpm
               ELSE 0
          END ) AS march_target_ecmp
       ,( CASE WHEN ps_month = '03' THEN ps_actual_ecpm
               ELSE 0
          END ) AS march_actual_ecpm
    FROM publisher_stats
    JOIN domain
        ON domain.dmn_id = ps_dmn_id
    LEFT JOIN langue
        ON langue.lng_id = domain.default_lng_id