I have a table which have schema like this
id name
1 jack
2 jack of eden
3 eden of uk
4 m of s
I want to execute a query which gives me count of words like this
count word
2 jack
2 eden
3 of
this means jack has been here 2 times, eden 2 times and of has been 3 times.
Hope you got the question, m trying too but not getting the right query or approach to it
thnx
Assuming your table is named
temp(probably not – change it to the right name of your table)I used a subquery for finding all the words in your table:
this query splits all the words from all records. I aliased it
words.Then I joined it with your table (in the query it’s called temp) and counted the number of occurences in every record.
You can also add:
update: for better performance we can replace the inner subquery with the results of a pipelined function:
first, create a schema type and a table of it:
then create the function:
now the query should look like: