sql >> データベース >  >> RDS >> Mysql

MYSQL-テーブルクエリをフラット化

    GROUP BYを定義する必要があります 句を入力し、MAXを使用します 必要な出力を取得するための集計:

      SELECT listup.NodeNumber As Node, listup.Station As Extension,
             MAX(CASE WHEN VoiceServer = 1 THEN KeyDescription ELSE NULL END) AS 'Key1',
             MAX(CASE WHEN VoiceServer = 2 THEN KeyDescription ELSE NULL END) AS 'Key2',
             MAX(CASE WHEN VoiceServer = 3 THEN KeyDescription ELSE NULL END) AS 'Key3',
             MAX(CASE WHEN VoiceServer = 4 THEN KeyDescription ELSE NULL END) AS 'Key4',
             MAX(CASE WHEN VoiceServer = 5 THEN KeyDescription ELSE NULL END) AS 'Key5',
             MAX(CASE WHEN VoiceServer = 6 THEN KeyDescription ELSE NULL END) AS 'Key6',
             MAX(CASE WHEN VoiceServer = 7 THEN KeyDescription ELSE NULL END) AS 'Key7',
             MAX(CASE WHEN VoiceServer = 8 THEN KeyDescription ELSE NULL END) AS 'Key8',
             MAX(CASE WHEN VoiceServer = 9 THEN KeyDescription ELSE NULL END) AS 'Key9',
             MAX(CASE WHEN VoiceServer = 10 THEN KeyDescription ELSE NULL END) AS 'Key10'
        FROM listup
    GROUP BY listup.NodeNumber As Node, listup.Station As Extension
    ORDER BY listup.NodeNumber, listup.Station
    

    NULL 長さがゼロの文字列よりも望ましいです。




    1. SQL Serverで日時を切り捨てるにはどうすればよいですか?

    2. mysql_escape_stringが非常に推奨されないのはなぜですか?

    3. Doctrine Backuptables

    4. MariaDB DAY()の説明