返された 2 つのフィールドに基づいて選択した結果のカウントを行いたいのですが、それを group by 句で行います。返されたフィールドの 1 つですが、部分文字列と patindex を使用して変更し、結果にあるコロンの後のすべてを取得するため、「紙」または「オンライン」という単語を含む列になります。紙とオンラインの結果の数を数えたいのですが、取得した結果は、変更したものではなく、フィールドの元の内容に基づいてカウントされます。これは私が今していることです:
select field1, field2,
case when substring(field3, patindex('%:%',field3)+1, 6) = 'Paper' then 'paper'
else 'online' end, count(field3) 'Count'
from theTable
group by field2, field1, field3
order by field2, field1
私も試しました:
select field1, field2,
count(case when substring(field3, patindex('%:%',field3)+1, 6) = 'Paper' then 'paper'
else 'online' end) 'Count'
from theTable
group by field2, field1, field3
order by field2, field1
私が求めているカウントを得るために何をする必要がありますか?