presto check if string contains substring code example

presto check if string contains substring

2

2 Examples

0
presto:default> select strpos('apache','ap') as string_position; 
by on

0
WITH greetings AS
  (SELECT 'hello world' as greeting_message UNION ALL
   SELECT 'Whats up' UNION ALL
   SELECT '' UNION ALL
   SELECT 'hello Sam' UNION ALL
   SELECT '' UNION ALL
   SELECT 'hello Ram' UNION ALL
   SELECT 'good morning, hello' UNION ALL
   SELECT '' UNION ALL
   SELECT 'the above row has null' UNION ALL
   SELECT 'Good morning Sir')

 SELECT count_if(regexp_like(greeting_message, '.*hello.*')) / cast(COUNT(1) as real) AS hello_percentage, 
       count_if(regexp_like(greeting_message, '.*morning.*')) / cast(COUNT(1) as real) AS morning_percentage 
FROM greetings
by on

Other Code Examples