group by first character

前端 未结 7 1664
天涯浪人
天涯浪人 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:22

    I think i know what you are trying to do...

    You should create a small reference table with a column 'letter' (letter, sort_order)

    You should your query as

    select l.letter, count(e.id) as employees from letter l left outer join employee e on l.letter = substr(e.first_name, 1,1)

    the other answer posted will give you unexpected results when there are no employees with a specific letter in their name...

    0 讨论(0)
提交回复
热议问题