我在SQL Server表Transactions
中有一个列A
。
我在该表中有大约1000行,并且在每行中我都有包含
组合的字符串 "@transaction --space of 3 characters---1" or "@transaction --space of 3 characters---0" these strings may be even repeated n number of times within the single row.
结果 - 我想检查所有
"@transaction --space of 3 characters---1" ones how many times repeated.
"@transaction --space of 3 characters---0" zeros how many times repeated.
我尝试了诸如
之类的查询Select * from A where transaction like '%@transaction --space of 3 characters---1%
Select * from A where transaction like '%@transaction --space of 3 characters---0%
但是这些不能给我想要的结果,因为单列中可能有更多的上述字符串。
有人可以建议如何分别计算所有这两个字符串的结尾1和0吗?
提前致谢
答案 0 :(得分:1)
试试这个
SELECT count (*) as [Count], 'Strings with 1' as [Comment]
FROM A
WHERE transaction like cast (@transaction as varchar(50)) +'???1%'
UNION ALL
SELECT count (*) as [Count], 'Strings with 0'
FROM A
WHERE transaction like cast (@transaction as varchar(50)) +'???0%'