w3resource

PostgreSQL String() Function: Get the employee id, email id to discard the last three characters


7. Write a query to get the employee id, email id to discard the last three characters.

Sample Solution:

Code:

SELECT employee_id, REVERSE(SUBSTR(REVERSE(email), 4)) as Email_ID 
FROM employees;

Sample table: employees


Output:

postgres=# SELECT employee_id, SUBSTR(REVERSE(email), 4) as Email_ID
postgres-# FROM employees;
 employee_id | email_id
-------------+----------
         100 | KS
         101 | HCOKN
         102 | HEDL
         103 | NUHA
         104 | REB
         105 | SUAD
         106 | ATAPV
         107 | EROLD
         108 | EERGN
         109 | VAFD
         110 | CJ
         111 | AICSI
         112 | RUMJ
         113 | PL
         114 | HPARD
         115 | KA
         116 | ABS
         117 | BOTS
         118 | MIHG
         119 | MLOCK
         120 | EWM
         121 | RFA
         122 | FUAKP
         123 | LLOVS
         124 | RUOMK
         125 | ANJ
         126 | KKIMI
         127 | NALJ
...
         197 | EEFK
         198 | NOCOD
         199 | RGD
         200 | AHWJ
         201 | TRAHM
         202 | P
         203 | VAMS
         204 | BH
         205 | GGIHS
         206 | IGW
(107 rows)

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming