Real-Time Examples of SQL Functions: Practical Applications and Use Cases
☰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.
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))