sql >> Databáze >  >> RDS >> Mysql

mysql pivoting - jak mohu načíst data ze stejné tabulky do různých sloupců?

můžete zkusit toto

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



  1. Prozkoumejte SQL Server Restore Database with Recovery vs No Recovery Options

  2. Kde změnit hodnotu lower_case_table_names=2 v systému Windows xampp

  3. Chyba dotazu s nejednoznačným názvem sloupce v SQL

  4. Jak funguje UTC_TIME() v MariaDB