SQL中包含字符串的记录数

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

我在一列中有两个字符串。我想要数数。

LIKE '%Alpha%' and LIKE '%Beta'%

我希望得到它们出现在表格中的次数。我认为这很容易使用qazxsw大便,但它似乎没有运作。

sql string count
2个回答
1
投票

你可以做聚合:

CASE

如果你想分开计数,那么你可以做条件聚合:

select count(*)
from table t
where col like '%Alpha%' and col like '%Beta%';

0
投票

如果你想将它们彼此分开计算:

select sum(case when col like '%Alpha%' then 1 else 0 end) as AlphaCnt,
       sum(case when col like '%Beta%' then 1 else 0 end) as BetaCnt
from table t;
© www.soinside.com 2019 - 2024. All rights reserved.