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

MySQL:Hvordan tilmelder jeg mig samme bord flere gange?

Du skal bruge flere LEFT JOINs :

SELECT 
    ticket.ticket_id,  
    a1.attr_val AS attr_val1,
    a2.attr_val AS attr_val2,
    a3.attr_val AS attr_val3
FROM ticket
    LEFT JOIN attr a1 ON ticket.ticket_id=a1.ticket_id AND a1.attr_type=1
    LEFT JOIN attr a2 ON ticket.ticket_id=a2.ticket_id AND a2.attr_type=2
    LEFT JOIN attr a3 ON ticket.ticket_id=a3.ticket_id AND a3.attr_type=3

Her er et eksempel:SQL Fiddle .



  1. MariaDB JSON_TABLE() Forklaret

  2. Pymysql Cursor.fetchall() / Fetchone() Returnerer ingen

  3. Forståelse af SQL Server Lockdown til Secure Database Environment

  4. Oracle SQL Syntaks:Citeret identifikator