Help on query, how to show sequential numbers for each group
From: Big George <jbeteta_at_gmail.com>
Date: Mon, 4 Oct 2010 12:36:09 -0700 (PDT)
Message-ID: <7e95acb9-92bc-48bd-9cf4-f5be9c37c3fa_at_t20g2000yqa.googlegroups.com>
Hello,
Date: Mon, 4 Oct 2010 12:36:09 -0700 (PDT)
Message-ID: <7e95acb9-92bc-48bd-9cf4-f5be9c37c3fa_at_t20g2000yqa.googlegroups.com>
Hello,
MyTable has missing records:
id_group id_column
1 1 1 2 1 3 1 5 1 9 2 1 2 2 2 4 2 6
As you see, it could be missed record 4,6,7 and 8 of group 1 and record 3 and 5 of group 2. That's is an example.
I need to show all sequential records, incluing missing ones, like this:
Id_group Id_column
1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 1 2 2 2 3 2 4 2 5 2 6
I try this query:
Select G.id_group, C.rownum id_column
from (select distinct id_group from MyTable) G
cross join (SELECT rownum FROM dual CONNECT BY LEVEL <= (select
max(id_column) from MyTable)) C
but it shows record 7, 8 and 9 as members of group 2.
Could somebody help me, please? Thanks. Received on Mon Oct 04 2010 - 14:36:09 CDT