Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

MYSQL - Ratakan Tabel Query

Anda perlu mendefinisikan GROUP BY klausa, dan gunakan MAX agregat untuk mendapatkan hasil yang Anda inginkan:

  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 lebih disukai daripada string panjang nol.




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. php:cara mengubah data string menjadi data numerik

  2. Tabel MySQL sebagai FIFO/Antrian

  3. Kembangkan React dengan full-stack (WAMP) secara lokal

  4. Cara terbaik untuk menyimpan nilai yang disandikan base64 di MySQL DB?

  5. Pesan kesalahan:Pengecualian di utas utama org.hibernate.HibernateException:Kesalahan saat mengakses aliran stax