Equivalent function to STUFF in SQL (GROUP_CONCAT in MySSQL / LISTAGG in Oracle)

前端 未结 1 1518
一整个雨季
一整个雨季 2020-12-10 05:54

Does anyone know if Firebird 2.5 has a function similar to the "STUFF" function in SQL?

I have a table which contains parent user records, and another table

相关标签:
1条回答
  • 2020-12-10 06:16

    It looks like you are in luck - Firebird 2.1 introduced a LIST() aggregate function which works like GROUP_CONCAT in MySQL, which allows a query like so:

    SELECT p.Name, LIST(c.Name, ', ')
    FROM parent p INNER JOIN child c on c.parentid = p.parentid
    GROUP by p.Name;
    

    Edit, re Ordering

    You may be able to influence ordering by pre-ordering the data in a derived table, prior to applying the LIST aggregation function, like so:

    SELECT x.ParentName, LIST(x.ChildName, ', ')
    FROM 
    (
      SELECT p.Name as ParentName, c.Name as ChildName
      FROM parent p INNER JOIN child c on c.parentid = p.parentid
      ORDER BY c.Name DESC
    ) x
    GROUP by x.ParentName;
    
    0 讨论(0)
提交回复
热议问题