1

TransactionsSQL Server テーブルに列があります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 で終わるこれら 2 つの文字列をすべて個別にカウントする方法を誰かが提案できますか?

前もって感謝します

4

1 に答える 1

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%'
于 2013-06-05T11:58:43.823 に答える