Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to translate the PostgreSQL array_agg function to SQLite?

This query works in PostgreSQL:

  Select    ot.MCode,array_to_string(array_agg(tk1.TName || ',' || ot.TTime), ' - ') as oujyu_name_list
    From    TR_A ot
    inner join MS_B tk1 on ot.Code = tk1.Code
    Where   ot.Code in (Select Code From TR_C ) 
    Group byot.MCode

but it does not work in SQLite, because SQLite does not have the array_agg() function. How can this query be converted to SQLite?

like image 678
D T Avatar asked Nov 14 '14 03:11

D T


1 Answers

For this query, you can use group_concat, which directly returns a string:

SELECT ..., group_concat(tk1.TName || ',' || ot.TTime, ' - ')
FROM ...
like image 166
CL. Avatar answered Nov 16 '22 02:11

CL.