r***@chrysler.com
2007-08-22 12:51:05 UTC
This seems like it should be easy,
but finding acceptable syntax has proven very difficult.
Given a table with multicolumn data,
and a multicolumn hierarchical index,
how can a "subtable" be selected that contains the
multicolumn data and a multicolumn subset of the index?
Assume a table with a data column and 3 column index.
create table lookup
(val char(1), maj integer, min integer, rel integer);
create unique index lookup_i1 on lookup
(maj desc,min desc,rel desc)
insert into lookup values
('c',3,3,2)
,('z',3,3,1)
,('o',3,2,3)
,('y',3,2,2)
,('r',3,1,1)
,('r',2,4,2)
,('e',2,3,4)
,('x',2,3,3)
,('w',2,3,2)
,('v',2,3,1)
,('c',2,2,1)
,('t',2,1,1)
,('l',1,2,1)
,('y',1,1,5)
,('u',1,1,2)
,('t',1,1,0)
;
Try to populate a table with a data column and 2 column index,
where the data is copied from the first row in the larger
table with the same first part of the index.
It would seem this should be easy to do with "group by"
and "max()" but no success so far.
create table result
(val char(1), maj integer, min integer);
create unique index result_i1 on result
(maj desc,min desc)
The goal is to find a subselect
select ... lookup ...
such that the contents of result are as follows.
insert into lookup values
('c',3,3,2)
-- ,('z',3,3,1) -- superceded by rel=2 for maj,min=3,3
,('o',3,2,3)
-- ,('y',3,2,2) -- both superceded by rel=3
-- ,('r',3,1,1)
,('r',2,4,2)
,('e',2,3,4)
-- ,('x',2,3,3) -- first row only for maj,min = 2,3
-- ,('w',2,3,2)
-- ,('v',2,3,1)
,('c',2,2,1)
,('t',2,1,1)
,('l',1,2,1)
,('y',1,1,5)
-- ,('u',1,1,2) -- superceded by first in 1,1 sublist
-- ,('t',1,1,0)
;
Problems so far include:
distinct seems to preclude carrying the columns (val)
that are not part of the unique index up the select
nesting.
join includes ALL the rows for each rel
aggregate functions and/or where operate on all the rows
not just within the group.
What am I missing?
TIA
but finding acceptable syntax has proven very difficult.
Given a table with multicolumn data,
and a multicolumn hierarchical index,
how can a "subtable" be selected that contains the
multicolumn data and a multicolumn subset of the index?
Assume a table with a data column and 3 column index.
create table lookup
(val char(1), maj integer, min integer, rel integer);
create unique index lookup_i1 on lookup
(maj desc,min desc,rel desc)
insert into lookup values
('c',3,3,2)
,('z',3,3,1)
,('o',3,2,3)
,('y',3,2,2)
,('r',3,1,1)
,('r',2,4,2)
,('e',2,3,4)
,('x',2,3,3)
,('w',2,3,2)
,('v',2,3,1)
,('c',2,2,1)
,('t',2,1,1)
,('l',1,2,1)
,('y',1,1,5)
,('u',1,1,2)
,('t',1,1,0)
;
Try to populate a table with a data column and 2 column index,
where the data is copied from the first row in the larger
table with the same first part of the index.
It would seem this should be easy to do with "group by"
and "max()" but no success so far.
create table result
(val char(1), maj integer, min integer);
create unique index result_i1 on result
(maj desc,min desc)
The goal is to find a subselect
select ... lookup ...
such that the contents of result are as follows.
insert into lookup values
('c',3,3,2)
-- ,('z',3,3,1) -- superceded by rel=2 for maj,min=3,3
,('o',3,2,3)
-- ,('y',3,2,2) -- both superceded by rel=3
-- ,('r',3,1,1)
,('r',2,4,2)
,('e',2,3,4)
-- ,('x',2,3,3) -- first row only for maj,min = 2,3
-- ,('w',2,3,2)
-- ,('v',2,3,1)
,('c',2,2,1)
,('t',2,1,1)
,('l',1,2,1)
,('y',1,1,5)
-- ,('u',1,1,2) -- superceded by first in 1,1 sublist
-- ,('t',1,1,0)
;
Problems so far include:
distinct seems to preclude carrying the columns (val)
that are not part of the unique index up the select
nesting.
join includes ALL the rows for each rel
aggregate functions and/or where operate on all the rows
not just within the group.
What am I missing?
TIA