Sunday, 15 July 2012

oracle - nasty Aggregation in SQLPLUS -



oracle - nasty Aggregation in SQLPLUS -

nasty aggregation in sqlplus

hi all, have next table:

col.1 col.2 2 1-v 4 2-vv 6 3-ec 8 2-gd 5-v c 2-ec e 2-gd 10 6-v 12 2-v 14 1-gd 14 1-v

what need aggregation on table , next table (group row col.2 using value after '-' [v, vv, ec, gd]):

type count ec 2 gd 3 v 5 vv 1

i not know how utilize "group by" clause task.

br hosen

one possible solution problem be:

select regexp_replace(col_2, '^\d+-', null), count(1) the_next_table grouping regexp_replace(col_2, '^\d+-', null);

enjoy.

ps: of course, solution dependent on presumption col.2 info of form <some number><the dash symbol><anything>. such case solution strips away <some number><the dash symbol> part , leaves <anything> aggregation.

oracle group-by sqlplus aggregation

No comments:

Post a Comment