Keresé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

  • 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