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.
Previous: Write a query to get the employee id, first name and hire month of an employee.
Next: Write a query to find all the employees which first name contains all the uppercase letter.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework