Like operator in Teradata with examples
Contents
Like Operator in Teradata
The Like operator is used for pattern matching in Teradata. It needs to specify in the WHERE clause to search the specific pattern in a column. There are two wildcards that used along with Like operator.
- % – The percent character is represents zero,one, or multiple characters
- _ – The underscore character is represents the single character.
Syntax of Like operator
1 2 3 |
SELECT * FROM <Database_Name.Table_Name> WHERE <column_name> LIKE <pattern_to_match>; |
We need to mention the column name that we want to match with the pattern. After the LIKE operator, we can specify the required pattern string for matching.
Example : Like operation in Teradata
Lets create the Food_Revenue table to show the use of LIKE operator in Teradata
In the table, we have one of the column as Food Name that contains all the food item names such as Pizza,Burger,Scilian Pizaa,Fried Chicken and so on.
Here we wants to calculate the revenue for Pizza which means that we need to sum the revenue of all the food items that contains Pizza.
- Scilian Pizza
- Pizza
- Sushi Pizza
Lets write the query with Like operator to get the required result in Teradata
1 2 |
Select * from Restaurant_DB.Food_Revenue Where FoodName Like '%Pizza%'; |
Output
Since we have put the pattern as ‘%Pizza%‘ in the Like operator, the select query returned all the records which has a sub string of Pizza as food name. From this result set, we can get the revenue of these items using SUM function.
1 2 |
Select SUM(TotalSellAmout) from Restaurant_DB.Food_Revenue Where FoodName Like '%Pizza%'; |
Recommended Articles
- How to use Qualify Row_number in Teradata?
- How to write nested Case statement in Teradata?
- Pivot function in Teradata with examples
- Replace the string using REGEXP_REPLACE function in Teradata