DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: Need columns in attributelist but not in the group by -expression

  1. #1
    Join Date
    Apr 2002
    Location
    Germany.Laudenbach
    Posts
    448

    Need columns in attributelist but not in the group by -expression

    Hi,

    i want A.FK_DATEI_DE,
    A.FK_DATEI_EN,
    A.FK_DATEI_MU*/

    in the attribute-list ( matches max(A.LIEFERDATUM))
    but not in the group by-expression,
    any idea

    select distinct
    A.FK_BERICHTSART,
    B.NAME,
    I.ISIN,
    IE.BOERSENKUERZEL,
    A.GESCHAEFTSJAHR,
    A.FK_BERICHTSZEITRAUM,
    B.FK_ENDEGESCHAEFTSJAHR,
    /*A.FK_DATEI_DE,
    A.FK_DATEI_EN,
    A.FK_DATEI_MU,*/
    MAX(A.LIEFERDATUM) as ALIEF
    from BERICHT A,
    EMITTENT_RESY B,
    INSTRUMENT I,
    INSTRUMENT_EXT IE
    where A.FK_STATUS >= 3
    and A.FK_EMITTENT = B.KUNDENNR
    and I.PRIMAERINSTRUMENT = 1 -- das soll bewirken, dass nur das jeweilige Primärinstrument berücksichtigt wird
    and I.FK_EMITTENT = A.FK_EMITTENT
    and I.INSTRUMENTID = IE.FK_INSTRUMENT(+)
    and 'DE0005003404' IN (SELECT ISIN FROM INSTRUMENT WHERE FK_EMITTENT = A.FK_EMITTENT)
    group
    by B.NAME,
    I.ISIN,
    IE.BOERSENKUERZEL,
    A.FK_BERICHTSART,
    A.GESCHAEFTSJAHR,
    A.FK_BERICHTSZEITRAUM,
    B.FK_ENDEGESCHAEFTSJAHR/*,
    A.FK_DATEI_DE,
    A.FK_DATEI_EN,
    A.FK_DATEI_MU*/
    order by ALIEF DESC

  2. #2
    Join Date
    May 2002
    Posts
    108
    For the expressions you have grouped if these columns
    A.FK_DATEI_DE, A.FK_DATEI_EN, A.FK_DATEI_MU will have only one value, or if you will only require the maximum or minimum value then u can use the MAX() or the MIN() for these columns in conjunction with the other column
    Never give up !

    Nanda Kumar - Vellore

  3. #3
    Join Date
    Apr 2002
    Location
    Germany.Laudenbach
    Posts
    448

    Thumbs up

    Originally posted by nandu
    u can use the MAX() or the MIN() for these columns in conjunction with the other column
    This worked !!
    Thanks nandu
    Orca

    select distinct
    A.FK_BERICHTSART,
    B.NAME,
    I.ISIN,
    IE.BOERSENKUERZEL,
    A.GESCHAEFTSJAHR,
    A.FK_BERICHTSZEITRAUM,
    B.FK_ENDEGESCHAEFTSJAHR,
    MAX(to_char(A.LIEFERDATUM, 'YYYY.MM.DD HH24:MI') || ';' || a.fk_datei_de || ';' || a.fk_datei_mu || ';' || a.fk_datei_en ) as ALIEF
    from BERICHT A,
    EMITTENT_RESY B,
    INSTRUMENT I,
    INSTRUMENT_EXT IE
    where A.FK_STATUS >= 3
    and A.FK_EMITTENT = B.KUNDENNR
    and I.PRIMAERINSTRUMENT = 1 -- das soll bewirken, dass nur das jeweilige Primärinstrument berücksichtigt wird
    and I.FK_EMITTENT = A.FK_EMITTENT
    and I.INSTRUMENTID = IE.FK_INSTRUMENT(+)
    and 'DE0005003404' IN (SELECT ISIN FROM INSTRUMENT WHERE FK_EMITTENT = A.FK_EMITTENT)
    group
    by B.NAME,
    I.ISIN,
    IE.BOERSENKUERZEL,
    A.FK_BERICHTSART,
    A.GESCHAEFTSJAHR,
    A.FK_BERICHTSZEITRAUM,
    B.FK_ENDEGESCHAEFTSJAHR
    order by ALIEF DESC

  4. #4
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Maybe you can use an inline view and put your group by query in the view and join it back to the results you want outside the view...
    Jeff Hunter

  5. #5
    Join Date
    Apr 2002
    Location
    Germany.Laudenbach
    Posts
    448
    Originally posted by marist89
    Maybe you can use an inline view and put your group by query in the view and join it back to the results you want outside the view...
    Yes, this is a possible technique too, but in this case i have problems to identify the unique row with the max-val.
    Orca

  6. #6
    Join Date
    May 2002
    Posts
    108
    You don't need to convert to to_char etc., It can be

    select distinct
    A.FK_BERICHTSART,
    B.NAME,
    I.ISIN,
    IE.BOERSENKUERZEL,
    A.GESCHAEFTSJAHR,
    A.FK_BERICHTSZEITRAUM,
    B.FK_ENDEGESCHAEFTSJAHR,
    Max(A.FK_DATEI_DE),
    Max(A.FK_DATEI_EN),
    Max(A.FK_DATEI_MU),
    MAX(A.LIEFERDATUM) as ALIEF
    from BERICHT A,
    ...
    ...
    ...
    Never give up !

    Nanda Kumar - Vellore

  7. #7
    Join Date
    Apr 2002
    Location
    Germany.Laudenbach
    Posts
    448
    No nando this does not work correct for my reason :

    I want the additional coulums of that ONE ROW which
    has the max-val and not the max-val of the GROUP;
    So it's ok!!
    Orca

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width