0

I have a dataset that looks like this:

enter image description here

And I would like to do a select query where I can set manually keywords (e.g. city, beautiful, rains, trees) and get a count of how many times these keywords appear. In this case the result should be

enter image description here

Siyual
  • 16,415
  • 8
  • 44
  • 58

1 Answers1

2

Assume that you have a table of keywords. You can then do:

select kw.word, count(d.city)
from keywords kw left join
     dataset d
     on d.description like concat('%', kw.word, '%')
group by kw.word;

The only problem with this is partial matches. So, "trees" would match the keyword "tree" (as well as "re" and "e" and so on). If you know you have no punctuation and can assume that words are separated by spaces, you can use:

select kw.word, count(d.city)
from keywords kw left join
     dataset d
     on concat(' ', d.description, ' ') like concat('% ', kw.word, ' %')
group by kw.word;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786