group by first character

前端 未结 7 1676
天涯浪人
天涯浪人 2020-12-03 04:16

I have a problem with a query in Oracle SQL.

I have a first_name column in an employees table. I want to group my records according to the

7条回答
  •  清歌不尽
    2020-12-03 05:06

    It almost sounds like you want 26 records returned with A, B, C as the first column and then a second column containing all the employee IDs in a delimited list. If so see question 468990 and/or this Ask Tom link. Something like (untested)

    SELECT SUBSTR(first_name,1,1), TO_STRING( CAST( COLLECT( employee_id ) AS ntt_varchar2 ) ) AS empIDs
    FROM   employees
    GROUP  BY
    SUBSTR(first_name,1,1);
    

提交回复
热议问题