Select groupping by one column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josué Maldonado

    Select groupping by one column

    Hello list,

    I have a table called pedh that looks like this:

    REFNO FECHA OCNUM PVD
    0199 10/12/2003 5224 632
    0199 10/12/2003 5224 632
    1264 10/18/2003 8991 210
    1264 10/18/2003 8991 210
    1264 10/18/2003 8991 210
    9093 10/20/2003 6895 520
    9093 10/20/2003 6895 520

    I need to select one record groupped by column refno, I tried using this
    code:

    select refno, max(fecha), max(ocnum), max(pvd) from pedh

    It seems to work fine, but is there another way to get the same result
    avoing use of aggregate functions?


    Thanks in advance




    --
    Josué Maldonado



    ---------------------------(end of broadcast)---------------------------
    TIP 6: Have you searched our list archives?



  • Bruno Wolff III

    #2
    Re: Select groupping by one column

    On Thu, Dec 18, 2003 at 15:09:52 -0800,
    Josué Maldonado <josue@lamundia l.hn> wrote:[color=blue]
    > Hello list,
    >
    > I have a table called pedh that looks like this:
    >
    > REFNO FECHA OCNUM PVD
    > 0199 10/12/2003 5224 632
    > 0199 10/12/2003 5224 632
    > 1264 10/18/2003 8991 210
    > 1264 10/18/2003 8991 210
    > 1264 10/18/2003 8991 210
    > 9093 10/20/2003 6895 520
    > 9093 10/20/2003 6895 520
    >
    > I need to select one record groupped by column refno, I tried using this
    > code:
    >
    > select refno, max(fecha), max(ocnum), max(pvd) from pedh[/color]

    I don't see how that could work. Maybe you left off group by. But if you
    did the aggreates could come from different rows, which might not be what
    you want.
    [color=blue]
    >
    > It seems to work fine, but is there another way to get the same result
    > avoing use of aggregate functions?[/color]

    You might be able to use distinct on instead of aggregates.

    ---------------------------(end of broadcast)---------------------------
    TIP 6: Have you searched our list archives?



    Comment

    • Josué Maldonado

      #3
      Re: Select groupping by one column

      Hello Bruno,

      Bruno Wolff III wrote:[color=blue][color=green]
      >>
      >>select refno, max(fecha), max(ocnum), max(pvd) from pedh[/color]
      >
      >
      > I don't see how that could work. Maybe you left off group by. But if you
      > did the aggreates could come from different rows, which might not be what
      > you want.[/color]

      I missed the group by 1, I'm sorry.
      [color=blue]
      >
      >[color=green]
      >>It seems to work fine, but is there another way to get the same result
      >>avoing use of aggregate functions?[/color]
      >
      >
      > You might be able to use distinct on instead of aggregates.[/color]

      Thanks



      ---------------------------(end of broadcast)---------------------------
      TIP 4: Don't 'kill -9' the postmaster

      Comment

      Working...