SQLite Select data from multiple rows returned as one row

后端 未结 3 2059
半阙折子戏
半阙折子戏 2020-12-30 17:56

I would like to know whether it is possible to use a SELECT statement in SQLite to merge the data from two rows into one, similar to how is suggested in the SQL Server forum

相关标签:
3条回答
  • 2020-12-30 18:04

    Doug's solution didn't work for me. The code below, however, did work for me but it's very slow...

    SELECT 
       a.ID, 
       a.Name AS Name1,
       (SELECT b.Name FROM Emp b 
                 WHERE b.ID = a.ID
                 AND b.Name != a.Name LIMIT 1) AS Name2
    FROM emp a 
    GROUP BY a.ID
    
    0 讨论(0)
  • 2020-12-30 18:13
    SELECT 
       a.ID, 
       COALESCE(a.Name,'') as "Name-1", 
       COALESCE((SELECT b.Name FROM Emp b 
                 WHERE b.ID = a.ID
                 AND b.rowid != a.rowid LIMIT 1),'') as "Name-2"
    FROM emp a 
    GROUP BY a.ID
    
    0 讨论(0)
  • 2020-12-30 18:16

    try this:::

    select id, group_concat(name) from emp group by id;

    ;)

    0 讨论(0)
提交回复
热议问题