|
|
Archives of the TeradataForum
Message Posted: Mon, 01 Jan 2007 @ 15:45:19 GMT
Subj: | | Re: STRING functions: Counting character occurrences |
|
From: | | Michael Larkins |
Kumar:
I didn't have a lot of time this morning and this could be a bit more efficient, but it might help get you started on the recursive:
with recursive dt (col, loc, partcol, cnt) as
(select col, position('A' in col), case loc when 0 then ' ' else
substring(col from index(col,'A')+1) end, case when loc > 0 then 1 else
0 end
from temp
union all
select col, position('A' in partcol) nwloc, case loc when 0 then ' '
else substring(partcol from loc+1) end, cnt+1
from dt
where loc > 0 and partcol <> ' ' )
sel col, max(cnt) from dt group by col
Hope this helps,
Michael Larkins
Certified Teradata Master
Certified Teradata SQL Instructor
| |