How to concatenate strings of a string field in a PostgreSQL 'group by' query?

前端 未结 14 1593
北荒
北荒 2020-11-22 02:37

I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table:

ID   COMPANY_ID   EMPLOYEE
1    1               


        
14条回答
  •  一个人的身影
    2020-11-22 03:04

    I found this PostgreSQL documentation helpful: http://www.postgresql.org/docs/8.0/interactive/functions-conditional.html.

    In my case, I sought plain SQL to concatenate a field with brackets around it, if the field is not empty.

    select itemid, 
      CASE 
        itemdescription WHEN '' THEN itemname 
        ELSE itemname || ' (' || itemdescription || ')' 
      END 
    from items;
    

提交回复
热议问题