Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2014
    Posts
    1

    Question Unanswered: DB2 - agregate with distinct row with select all columns

    Experts,

    My table

    col1 col2 col3 DESC Order#
    a 10 CD aaaa 110
    a 20 RD aaab 110
    a 30 GX aaac 110
    a 50 F3 aadd 245
    a 15 T1 aatt 470
    a 12 GR aa11 470
    a 20 BJ aaee 470
    a 27 JU aabb 470


    Basically, I need to another column, which should have the total number of orders ( group by order#)
    Any help is greatly appreciated.
    Thank You

    The output needed.
    col1 col2 col3 DESC Order# Count
    a 10 CD aaaa 110 3
    a 20 RD aaab 110 3
    a 30 GX aaac 110 3
    a 50 F3 aadd 245 1
    a 15 T1 aatt 470 4
    a 12 GR aa11 470 4
    a 20 BJ aaee 470 4
    a 27 JU aabb 470 4

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Adding
    Code:
     count(*) over (partition by order#)
    to the SELECT list should help.
    ---
    "It does not work" is not a valid problem statement.

Tags for this Thread

Posting Permissions

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