Einzelnen Beitrag anzeigen

jobo

Registriert seit: 29. Nov 2010
3.072 Beiträge
 
Delphi 2010 Enterprise
 
#8

AW: Suchfunktion mit "Gruppierung"

  Alt 5. Mär 2011, 20:55
Hier sind meine Daten /Ergebnisse. Vielleicht ist es nicht was Du haben wolltest, dann brauchst Du das SQL ja so auch nicht


Code:
SELECT e.id, e.f_hits, e.f_cat_id, f_word, e.f_status_id
  FROM tab_entries e
  JOIN tab_search_index i
    ON i.f_entry_id = e.id
Ergebnis
Code:
ID   F_HITS   F_CAT_ID   F_WORD   F_STATUS_ID
1   20   1   Stadt   1
2   22   3   LAnd   1
1   5   2   Stadt   2
2   9   3   LAnd   2
1   11   3   Stadt   2
1   33   4   Stadt   2
1   12   4   Stadt   1
1   13   4   Stadt   2
1   9   3   Stadt   2
1   12   1   Stadt   1
1   13   1   Stadt   2

Code:
      select o.*, s.*
        from (select id,
                     f_hits,
                     f_cat_id,
                     f_word,
                     f_status_id,
                     row_number() over(partition by f_cat_id order by f_hits) as TopOf
                from (SELECT e.id, e.f_hits, e.f_cat_id, f_word, e.f_status_id
                        FROM tab_entries e
                        JOIN tab_search_index i
                          ON i.f_entry_id = e.id
                       WHERE i.f_word = 'Stadt' --'Fluss'
                      ) i) o,
             tab_entries_status s
       where o.TopOf < 3
         and s.id = o.f_status_id
       order by o.f_cat_id, o.f_hits desc
Code:
ID   F_HITS   F_CAT_ID   F_WORD   F_STATUS_ID   TOPOF   ID   F_STATUS_NAME
1   13   1   Stadt   2   2   2   unfertich
1   12   1   Stadt   1   1   1   fertich
1   5   2   Stadt   2   1   2   unfertich
1   11   3   Stadt   2   2   2   unfertich
1   9   3   Stadt   2   1   2   unfertich
1   13   4   Stadt   2   2   2   unfertich
1   12   4   Stadt   1   1   1   fertich

Für MySQL gibts aber doch einige Seiten zum Thema,
Analytic Functions nachbilden. Das Suchwort wäre also "Analytic Functions mySQL"

Die Formatierung sieht doof aus, keine Ahnung ob das besser geht. Als Screenshot ist es besser lesbar, aber so als Text kann man die Zahlen noch weiter nutzen.
Gruß, Jo
  Mit Zitat antworten Zitat