SQLITE 使用左连接排序 group_concat
SQLITE ordering group_concat with a left join
我有以下查询
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 中执行此操作?
我找到了以下 link
Sqlite group_concat ordering
但我不知道如何让左连接在那里
谢谢
只需获取所有你想要的数据,对其进行排序,然后聚合即可:
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 ...);
我有以下查询
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 中执行此操作?
我找到了以下 link
Sqlite group_concat ordering
但我不知道如何让左连接在那里
谢谢
只需获取所有你想要的数据,对其进行排序,然后聚合即可:
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 ...);