After few hours of googlling and debugging finally i have got it solved.
I have used combination of char_length and replace to achieve this task.
What i end up with is as below.
select *,(
(char_length(name) - char_length(replace(name,'sam',''))) +
(char_length(description) - char_length(replace(description,'sam','')))
) / char_length('sam') as SearchCount
from
product
order by
SearchCount desc
above query is CASE SENSITIVE but do not worry i have also solved it with CASE-INSESITIVE see below query.
select *,
(
(char_length(name) - char_length(replace(LOWER(name),LOWER('Sam'),''))) +
(char_length(description) -
char_length(replace(LOWER(description),LOWER('Sam'),'')))
) / char_length('sam') as SearchCount
from
product
order by
SearchCount desc
after having this query all we need to do is add WHERE
clause to make it work.
Hope this will help other People too.
Thanks for help (All the people who answered and deleted and comment.)