0
我有一個表,看起來像這樣:基於左側字符計數?
ID Location
1 AAA123
1 AAA133
1 AAA832
1 BBB929
1 BBB420
我怎麼能算和組由前3個字符,這樣的結果是這樣的:
ID AAA_Count BBB_count
1 3 2
我想是這樣的:
select [ID], Location,
case when left(location, 3) = 'AAA' then count(location) end as 'AAA',
case when left(location, 3) = 'BBB' then count(location) end as 'BBB',
from Table
group by [ID], left(location, 3)
任何幫助表示讚賞。
謝謝。
始終指定您正在使用的軟件和服務器版本。 – FLICKER