gpt4 book ai didi

sqlite - 带左联接的SQLITE排序group_concat

转载 作者:行者123 更新时间:2023-12-03 19:36:49 28 4
gpt4 key购买 nike

我有以下查询

        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中执行此操作?

我找到了以下链接

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 ...);

关于sqlite - 带左联接的SQLITE排序group_concat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33682598/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com