Hirdetés

Ú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

Új hozzászólás Aktív témák