Aja*_*ary 2 mysql contains presto string-function amazon-athena
我在雅典娜与 Serde 有一张桌子ORC。该表包含一个名为 的字符串列greeting_message。它也可以包含空值。我想找出表中有多少行具有特定文本作为模式。
假设我的示例数据如下所示:
|greeting_message |
|-----------------|
|hello world |
|What's up |
| |
|hello Sam |
| |
|hello Ram |
|good morning, hello |
| |
|the above row has null |
| Good morning Sir |
Run Code Online (Sandbox Code Playgroud)
现在对于上表,如果我们看到总共有 10 行。其中 7 个不具有 null 值,其中 3 个仅具有 null/空值。
我想知道包含特定单词的行的百分比是多少。
例如,考虑这个词hello。它存在于 4 行中,因此此类行的百分比为 4/10,即 40%。
另一个例子:这个词morning出现在 2 条消息中。因此,此类行的百分比为 2/10,即 20%。
请注意,我null也在考虑分母的计数。
SELECT SUM(greeting_message LIKE '%hello%') / COUNT(*) AS hello_percentage,
SUM(greeting_message LIKE '%morning%') / COUNT(*) AS morning_percentage
FROM tablename
Run Code Online (Sandbox Code Playgroud)