SQL中的多个单词计数

问题描述 投票:0回答:1

我需要在特定的列中找到一个单词列表,“发生的事情的描述”

最多可容纳500个或更多字符。我有下面的脚本可以正常工作

但是我如何用要查找的单词的实际名称替换名称列1.2.3,并在其旁边加上总数。

只是无法让它显示简单的问题。

 select GROUPING_ID ( Amoxicillin  ,Atorvastatin ) as Name  ,count(*) as Total  
 from ( select case when [description_of_what_happened] like '%Amoxicillin%' 
 then 1 else 0 end as  Amoxicillin ,        
 case when [description_of_what_happened] like '%Atorvastatin%' 
 then 1 else 0 end as  Atorvastatin
 FROM "NAME OF TABLE"    
 group by grouping sets (() ,(Amoxicillin),(Atorvastatin))  
 having  coalesce (Amoxicillin,1)  != 0 and coalesce (Atorvastatin,1)  != 0     
 order by grouping_id (Amoxicillin,Atorvastatin) 

第3行是总数,我需要第1行和第2行以显示产品名称结果如下

 Name                 Total
 1                        7
 2                        9
 3                        4112
sql counting
1个回答
0
投票

您可以使用字符串代替标志:

© www.soinside.com 2019 - 2024. All rights reserved.