Új hozzászólás Aktív témák
-
tm5
tag
válasz
Apollo17hu
#5468
üzenetére
Ez talán még jobb, csak annyi kéne még hozzá, hogy adnék egy "minimum rank" értéket a t2 táblához és a query végén ahhoz hasonlítanám a match_rate-et és akkor tovább csökkennne a false pozitiv:
select t1.*, tt.kategoria
from t1
left join
(
select t.*, RANK() OVER(PARTITION BY t.id ORDER BY t.match_rate desc) AS rnum
from
(
select
t1.id
,t2.kategoria
,
(case when ifnull(t1.m1,'*') != ifnull(t2.m1,'*') then 0 when ifnull(t1.m1,'*') = ifnull(t2.m1,'%') then 1 else 0 end) +
(case when ifnull(t1.m2,'*') != ifnull(t2.m2,'*') then 0 when ifnull(t1.m2,'*') = ifnull(t2.m2,'%') then 1 else 0 end) +
(case when ifnull(t1.m3,'*') != ifnull(t2.m3,'*') then 0 when ifnull(t1.m3,'*') = ifnull(t2.m3,'%') then 1 else 0 end) +
(case when ifnull(t1.m4,'*') != ifnull(t2.m4,'*') then 0 when ifnull(t1.m4,'*') = ifnull(t2.m4,'%') then 1 else 0 end) +
(case when ifnull(t1.m5,'*') != ifnull(t2.m5,'*') then 0 when ifnull(t1.m5,'*') = ifnull(t2.m5,'%') then 1 else 0 end) +
(case when ifnull(t1.m6,'*') != ifnull(t2.m6,'*') then 0 when ifnull(t1.m6,'*') = ifnull(t2.m6,'%') then 1 else 0 end) +
(case when ifnull(t1.m7,'*') != ifnull(t2.m7,'*') then 0 when ifnull(t1.m7,'*') = ifnull(t2.m7,'%') then 1 else 0 end) +
(case when ifnull(t1.m8,'*') != ifnull(t2.m8,'*') then 0 when ifnull(t1.m8,'*') = ifnull(t2.m8,'%') then 1 else 0 end) as match_rate
, t1.m1
, t1.m2
, t1.m3
, t1.m4
, t1.m5
, t1.m6
, t1.m7
, t1.m8
from t1 join t2
--order by 1,3 desc;
) t
) tt on t1.id = tt.id and tt.rnum = 1 and tt.match_rate > 0 -
tm5
tag
válasz
Apollo17hu
#5468
üzenetére
Hát én valamni ilyesmivel indítanék:
select t.*, ROW_NUMBER() OVER(PARTITION BY t.id ORDER BY t.match_rate desc) AS row_num2
from
(select
t1.id
,t2.kategoria
,
(case when ifnull(t1.m1,'*') != ifnull(t2.m1,'%') then -100 when ifnull(t1.m1,'*') = ifnull(t2.m1,'%') then 1 else 0 end) +
(case when ifnull(t1.m2,'*') != ifnull(t2.m2,'%') then -100 when ifnull(t1.m2,'*') = ifnull(t2.m2,'%') then 1 else 0 end) +
(case when ifnull(t1.m3,'*') != ifnull(t2.m3,'%') then -100 when ifnull(t1.m3,'*') = ifnull(t2.m3,'%') then 1 else 0 end) +
(case when ifnull(t1.m4,'*') != ifnull(t2.m4,'%') then -100 when ifnull(t1.m4,'*') = ifnull(t2.m4,'%') then 1 else 0 end) +
(case when ifnull(t1.m5,'*') != ifnull(t2.m5,'%') then -100 when ifnull(t1.m5,'*') = ifnull(t2.m5,'%') then 1 else 0 end) +
(case when ifnull(t1.m6,'*') != ifnull(t2.m6,'%') then -100 when ifnull(t1.m6,'*') = ifnull(t2.m6,'%') then 1 else 0 end) +
(case when ifnull(t1.m7,'*') != ifnull(t2.m7,'%') then -100 when ifnull(t1.m7,'*') = ifnull(t2.m7,'%') then 1 else 0 end) +
(case when ifnull(t1.m8,'*') != ifnull(t2.m8,'%') then -100 when ifnull(t1.m8,'*') = ifnull(t2.m8,'%') then 1 else 0 end) as match_rate
, t1.m1
, t1.m2
, t1.m3
, t1.m4
, t1.m5
, t1.m6
, t1.m7
, t1.m8
from t1 join t2
--order by 1,3 desc;
) t
de e kőré még kell valami ilyesmi:select t1.*, tt.kategoria
from t1
left join
(
-- ide jon az elozo query
) tt on t1.id = tt.id and tt.rnum = 1 and tt.match_rate != -800
De ez még nem tökéletes. Van benne néhány fal pozitív kategória.Azért szedtem ketté, mert azzal a belső queryvel még kell játszani és finomhangolni a match_rate-et
Jah és remélem nem olyan sok rekord van egyik táblában sem, mert azért a descartes szorzat befigyel rendesen.
Új hozzászólás Aktív témák
- Lenovo ThinkPad T14s Gen 3 i5-1245U 14" FHD+ 16GB 1TB 1 év teljeskörű garancia
- Apple Watch Series 9 41mm Pink 96% (1év Garancia)
- CSÍKOS! MacBook Pro 16" M1 Pro 16GB 512GB Gar.
- Dell Latitude 3301 Core i5-8265U CPU / 8GB DDR4 RAM (Zsanér törött)
- HP EliteOne 800 G6 All-in-One i5-10500 16GB 512GB 24" Érintőkijelző!! 1 év garancia
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

