我有以下查询
let Query = "SELECT LEVELS1.ID, LEVELS1.NAME, GROUP_CONCAT(FRAMEWORKLEVELS1.NAME,'&/?') AS DATA FROM LEVELS1 LEFT JOIN FRAMEWORKLEVELS1 ON LEVELS1.ID = FRAMEWORKLEVELS1.LEVELID WHERE FRAMEWORKID = :ID GROUP BY FRAMEWORKID"
产生以下
DATA = "Level1&/?Level4&/?Level2&/?Level3";
ID = 1;
NAME = "Title";
我想要做的是订购GROUP_CONCAT,但我如何在SQLITE中执行此操作?
我找到了以下链接
但我无法弄清楚如何在那里获得左连接
由于
答案 0 :(得分:1)
只需获取所需的所有数据,对其进行排序,然后对其进行汇总:
SELECT ID,
Name,
group_concat(LevelName, '&/?') AS Data
FROM (SELECT Levels1.ID AS ID,
Levels1.Name AS Name,
FrameworkLevels1.Name AS LevelName
FROM Levels1
LEFT JOIN FrameworkLevels1 ON Levels1.ID = FrameworkLevels1.LevelID
WHERE FrameworkID = :ID
ORDER BY ...);