Real-Time Examples of SQL Functions: Practical Applications and Use Cases

Rumman Ansari   Software Engineer   2024-07-21 09:37:11   5608  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Real time example, where we can use LEN(), CHARINDEX() and SUBSTRING() functions. Let us assume we have table as shown below.

Real time example SQL Function

Write a query to find out total number of emails, by domain. The result of the query should be as shown below.

Code:


Select SUBSTRING(Email, CHARINDEX('@', Email) + 1,
LEN(Email) - CHARINDEX('@', Email)) as EmailDomain,
COUNT(Email) as Total
from TableEmployee
Group By SUBSTRING(Email, CHARINDEX('@', Email) + 1,
LEN(Email) - CHARINDEX('@', Email))