【发布时间】:2021-02-03 10:02:21
【问题描述】:
我有一个类似于以下结构的表格。我需要根据 MessageValue 列的值获取失败、成功和部分成功的计数。如果 Messagevale 列包含“失败”,则为失败,“成功”被视为成功,“部分成功”为部分失败。所以我需要在计数中检查 LIKE 标准,并且我还需要根据日期。我尝试使用 Group by 计数,但没有得到我需要的。
Date MessageValue
-----------------------------------------------
10/18/2020 Process failed some text here
10/18/2020 Process success some text here
10/19/2020 Partial success some text here
10/19/2020 Process failed some text here
10/19/2020 Process failed some text here
10/19/2020 Process partial success some text here
10/20/2020 Process partial success some text here
------------------------------------------------
所以输出应该如下所示。
Date Success Failure Partial Failure
-----------------------------------------------------------------
10/18/2020 1 1 0
10/19/2020 1 2 1
10/20/2020 0 0 1
【问题讨论】:
-
sum(case when col like '%failure%' then 1 else 0 end)等
标签: sql count pivot aggregate-functions sql-like