On Oct 25, 8:41*am, Dawid Zolkiewicz <j_e_l_l_...@tenbit.plwrote:
Quote:
Hello
>
I'm new here, so at the beginning I'd like to say hello for everybody.
>
First I'll describe my problem.
>
There is db2 database :) with about 0.5 mln people. Every person has
three features. These features have allowable values and also are stored
in db. I have to prepare query to find all possible combinations ok there
features and for every combination find one person having them.
>
So far I have query to find combinations but I can’t limit number of
people to 1. My idea was to connect values from three columns to one, so
I have:
>
+-----------+-----------+-----------+-----------+-----------+
|feature 1 *|feature 2 *|feature 3 *|1+2+3 * * *|prsn ID * *|
+-----------+-----------+-----------+-----------+-----------+
| * * A * * | * * B * * | * * C * * | A/B/C * * | * * * * * |
+-----------+-----------+-----------+-----------+-----------+
| * * D * * | * * E * * | * * F * * | D/E/F * * | * * * * * |
+-----------+-----------+-----------+-----------+-----------+
>
And my idea was to force query to show in table only unique values in 4th
column. But I don't know how to do that. Unfortunately, for some reason
option ROW_NUMBER doesn't work.
>
I'll be very thankful for any ideas.
>
Dawid
The following is just a skeletal one to show how your query can be
outlined, please customize it to your need.
The table arun.people_test has 4 columns, name, q1,q2,q3.
db2 "select * from arun.people_test"
Q1 Q2 Q3 NAME
-- -- -- -------------------------
a a a arun
a b b sandy
a b b sandy1
a a a arun1
4 record(s) selected.
with temp1(q1,q2,q3) as
(select q1,q2,q3 from arun.people_test group by q1,q2,q3),
temp2(q1,q2,q3,name,r) as (select t.q1,t.q2,t.q3,p.name,row_number()
over(partition by t.q1,t.q2,t.q3) as r from temp1 t,arun.people_test
p where t.q1=p.q1 and t.q2=p.q2 and t.q3 = p.q3)
select * from temp2 where r=1
Q1 Q2 Q3 NAME R
-- -- -- ------------------------- --------------------
a a a arun 1
a b b sandy 1