SQLITE: merging rows into single row if they share a column

后端 未结 3 869
别那么骄傲
别那么骄傲 2021-02-10 02:53

From a previous post, I have the following view in sqlite3:

CREATE View AttendeeTableView AS

SELECT  (LastName || \" \" || FirstName) as AttendeeName,  
                


        
3条回答
  •  生来不讨喜
    2021-02-10 03:23

    I'm thinking a inner select might help, like:

    CREATE View AttendeeTableView AS
    
    SELECT  (LastName || " " || FirstName) as AttendeeName,  
    
    (
      select CompanyName
    FROM    Attendee A_innner 
    JOIN    CompanyAttendeeRelation CAR  /* is this where company name is? */  
    ON      on CAR.AttendeeId = A.AttendeeId /* if not remove the joins and CAR */
    WHERE   A_inner.last_name = A_outer.last_name and
            A_inner.first_name = A_outer.first_name
    ),
    PhotoURI,
    CAR.CompanyId,
    CAR.AttendeeId 
    
    
    FROM    Attendee A_outer 
    JOIN    CompanyAttendeeRelation CAR_outer  
    ON      on CAR_outer.AttendeeId = A_outer.AttendeeId 
    
    GROUP by LastName,FirstName
    ORDER BY LastName, FirstName;
    

提交回复
热议问题