How to count occurrences of a character in a string in presto?

by dalton_moen , in category: Third Party Scripts , 4 months ago

How to count occurrences of a character in a string in presto?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by aniya.jaskolski , 4 months ago

@dalton_moen 

In Presto, you can count the occurrences of a character in a string using the following query:

1
2
3
4
5
6
SELECT 
    COUNT(*)
FROM 
    table_name
WHERE 
    column_name LIKE "%character%";


Replace "table_name" with the name of your table and "column_name" with the name of the column that contains the string you want to search in. Replace "character" with the character you want to count the occurrences of.


This query uses the LIKE operator to search for the specified character within the string in the column, and then counts the number of occurrences.