Announcement

Collapse
No announcement yet.

Wieder mal ein Verständnisproblem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wieder mal ein Verständnisproblem

    Hallo Forum,

    ich habe wieder mal ein Verständnisproblem.
    Ich habe mehrere Tabellen tmd = Artikel, tmh = Artikel-Historie, tu = Benutzer und tpd = Benutzerdaten.
    Jeder Artikel hat eine part_id - part_version z.B. 0815 - A, 0815 - B, 0815 - C....
    zu der dieser Artikelversionen 0815 - A, 0815 - B, 0815 - C gibt es diverse Historien-Einträge.
    Die Historieneinträge sind mit Transition benannt und haben ein Datum.
    Ich möchte pro Artikel-Version aus den Historieneinträgen nur die Transition mit dem aktuellesten Datum
    auslesen.

    Code:
    select tmd.part_id, tmd.part_version, tmd.pse_konstr, tmd.c_uic, tu.c_name, tu.c_ic, tpd.s_user, tpd.s_first_name, tmh.function, tmh.memo_ger, tmh.change_status, tmh.modify_name, tmh.modify_date
    from t_master_dat tmd, t_master_his tmh, t_user tu, t_prs_dat tpd
    where tmd.c_uic = tu.c_ic
    and tu.c_ic = tpd.c_ic(+)
    and (tmd.c_id = tmh.c_id_1 
    and tmh.function = 'TRANSITION')
    order by tmd.part_id asc, tmd.part_version asc, tmh.modify_date;
    Egal was ich versuche, ich scheitere entweder daran, dass ich zuviele Einträge bekomme oder ich bekomme aus den z.b. 3 Artikelversionen eine Willkürliche

    Code:
    select tmd.part_id, tmd.part_version, tmd.pse_konstr, tmd.c_uic, tu.c_name, tu.c_ic, tpd.s_user, tpd.s_first_name, tmh.function, tmh.memo_ger, tmh.change_status, tmh.modify_name, tmh.modify_date
    from t_master_dat tmd, t_master_his tmh, t_user tu, t_prs_dat tpd
    where tmd.part_id = '100142'
    and tmd.c_uic = tu.c_ic(+)
    and tu.c_ic = tpd.c_ic(+)
    and tmd.c_id = tmh.c_id_1 
    and tmh.function = 'TRANSITION'
    and tmh.modify_date = (select max(tmh.modify_date)
                           from t_master_dat tmd, t_master_his tmh 
                           where tmd.part_id = '100142'
                           and tmd.c_id = tmh.c_id_1
                           and tmh.function = 'TRANSITION')
                           order by tmh.modify_date desc;
    Wo liegt den hier mein Gedanken Fehler?

    Danke und Gruß
    Stephan

  • #2
    Das sieht nicht so schlecht aus. So als Schnellschuss würde ich mir mal anschauen, was mit der Artikelversion ist. Die berücksichtigst Du nicht, bei der Maxoperation, obwohl Du schreibst, dass Du das pro Artikelversion wissen willst.
    Gruß, defo

    Comment


    • #3
      Hallo defo,

      ja genau da liegt ja mein Problem. Ich kriege momatan, gedanklich den Zusammenhang nicht hin, wie ich in der max-Abfrage die Version mit einbinden kann. Da es ja z.B. drei Versionen geben kann und ich die Anzahl oder Versionen nicht kenne fehlt mir hier die zündende Idee!
      Aber danke für den Hinweis!

      Gruß
      Stephan

      Comment


      • #4
        Ich würde sagen, Du lässt sie einfach in der max Abfrage mit ausgeben.
        Gruß, defo

        Comment


        • #5
          Hallo defo,

          das hatte ich schon probiert:
          Code:
          select max(tmh.modify_date), tmd.part_version
                                 from t_master_dat tmd, t_master_his tmh 
                                 where tmd.part_id = '100142'
                                 and tmd.c_id = tmh.c_id_1
                                 and tmh.function = 'TRANSITION'
                                 order by tmh.modify_date desc;
          Dann bekomme ich einen Fehler:
          Fehler beim Start in Zeile 1 in Befehl:
          select max(tmh.modify_date), tmd.part_version
          from t_master_dat tmd, t_master_his tmh
          where tmd.part_id = '100142'
          and tmd.c_id = tmh.c_id_1
          and tmh.function = 'TRANSITION'
          order by tmh.modify_date desc
          Fehler bei Befehlszeile:1 Spalte:29
          Fehlerbericht:
          SQL-Fehler: ORA-00937: keine Gruppenfunktion für Einzelgruppe
          00937. 00000 - "not a single-group group function"
          *Cause:
          *Action:


          Und da war es wieder mein Problem

          Danke und Gruß
          Stephan

          Comment


          • #6
            Du musst das unaggregierte (zusätzliche) Feld per Group By Clause "anmelden".
            Falls Du aus der mySQL Welt kommst, da ist sowas nicht (unbedingt) nötig, ansonsten geht es nicht bzw. selbst by mySQL ist es dringend zu empfehlen, nicht aggregierte Felder immer per Group By zu handhaben.
            Gruß, defo

            Comment


            • #7
              So, meinem Ziel wieder einen Schritt näher gekommen.

              Allerdings nur einen kleine Schritt.
              Code:
              select tmd.part_version, max(tmh.modify_date)
              from t_master_dat tmd, t_master_his tmh 
              where tmd.part_id = '100142'
              and tmd.c_id = tmh.c_id_1
              and tmh.function = 'TRANSITION'
              group by tmd.part_version;
              Möchte ich jetzt mehr Felder rein bringen bekomme ich den Fehler ORA-00979 Kein Group by-Ausdruck

              Ich hoffe ich bekomme das auch noch hin.

              Stephan

              Comment


              • #8
                Du kannst nur Felder aufnehmen, die auch in der Selectliste stehen.
                Weitere Felder machen hier in Deinem wohl auch keinen Sinn, oder?
                Gruß, defo

                Comment

                Working...
                X