For my problem, I'm trying to find the category with the highest count of words within various sentences:
Table 1:
| Word | Category |
|---|---|
| 'Rain' | A |
| 'He' | A |
| 'France' | C |
| ... | ... |
| 'Work' | B |
Table 2:
| ID | Sentence |
|---|---|
| 1 | 'I'd like to go to France sometime.' |
| 2 | 'He won't come in a rain like this.' |
| 3 | 'They agreed to work together.' |
| ... | ... |
Ideally I would like to create a table like this:
Result:
| ID | Sentence | Category with highest word count |
|---|---|---|
| 1 | 'I'd like to go to France sometime.' | C |
| 2 | 'He won't come in a rain like this.' | A |
| 3 | 'They agreed to work together.' | B |
| ... | ... | ... |
My plan was to create columns for each word and then aggregate them by their categories to find the category with the highest word count for each ID, but the code I am planning to use requires a lot of manual input. Is there a better way to do this?
select ID,
Sentence
regexp_count(Assignee, 'Rain') + regexp_count(Assignee, 'He') + ... as CategoryA_Count
... as CategoryB_count
... as CategoryC_count
from Table 2```