Home > front end >  How do I select/query a string (# of characters varies) before a delimiter in Postgres SQL?
How do I select/query a string (# of characters varies) before a delimiter in Postgres SQL?

Time:10-15

I'm new to SQL. I've been practicing a lot recently. I've stumbled into this problem (please see imgur link)

How do I do the ff:

  1. Select/query the each degrees before a delimiter and show it in a new--column degrees (as shown in the table)
  2. For those without a degree, like example Mansoon Ahmed, reflect in column degrees as blank

Link to the Table--> https://imgur.com/TEP08NF

Thanks for all the help! Have a great day ahead!

CodePudding user response:

Use split_part() to get the part before the string:

SELECT CASE WHEN strpos(col, ',') <> 0
            THEN trim(split_part(col, ',', 1))
       END AS degree
FROM tab;
  • Related