SQLITE中的Group Contact in GROUP Contact

时间:2014-07-31 16:27:02

标签: sqlite

我想在GROUP_CONCAT

中添加订单

请求

        SELECT LRU.InstanceDesc as lru , 
GROUP_CONCAT((DataSourceGroup.DataSourceGroupID||'~'||TYPE||'~'||DataSource.`NDOID`||'~'||DataSource.Name ),'@') as data_souce , 

        FROM (SELECT DISTINCT TYPE,DataSourceGroupID,EQID,LRUID,DataFieldID FROM 
EquationDataPresort) EquationDataPresort    

        LEFT OUTER JOIN DataSource ON (DataSourceGroup.DataSourceID = DataSource.DataSourceID)  

        WHERE LRU.LRUID = '406' AND EquationDataPresort.`DataSourceGroupID` > -1 AND 
EquationDataPresort.EQID = '-1' GROUP BY LRU.InstanceDesc

我想订购DataSource.Name。我怎么能这样做?

由于

1 个答案:

答案 0 :(得分:2)

documentation说:

  

连接元素的顺序是任意的。

如果您从行已经具有正确顺序的子查询中获取值,您可以希望保留订单:

SELECT lru,
       GROUP_CONCAT(data_source, '@') AS data_source
FROM (SELECT LRU.InstanceDesc AS lru,
             DataSourceGroup.DataSourceGroupID||'~'||... AS data_source
      FROM ...
      LEFT OUTER JOIN ...
      WHERE ...
      ORDER BY 1, 2)
GROUP BY lru