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

Thread: SQL help

  1. #1
    Join Date
    Nov 1999
    Posts
    226
    HI

    I have a table in which the serial numbers and the totals are being repeated . I want to get the count of distinct rows as well as the total of those rows.

    Let me know how can i write it

    eg

    SNO TOTAL

    1 10
    1 10
    2 5
    3 10
    3 10

    i want distinct count fo rows and total for them is same
    SQL

    answer I am expecting in this case is

    3 25

    let me know




  2. #2
    Join Date
    Jan 2001
    Posts
    153
    hi,

    first of all u ve not mentioned the version currently u r working with...but i can give u the solution on oracle 8.0.5.

    say u have 2 colums slno, total

    SQLWKS> select * from test
    2>
    SLNO TOTAL
    ---------- ----------
    1 10
    1 10
    2 5
    3 10
    3 10

    5 Rows Selected

    --query

    select (select count(bb) from(select count(slno) bb from test group by slno)) count,
    bb total
    from
    (select
    sum(total) bb
    from
    test
    where
    rowid in (select max(rowid) from test
    group by slno)
    )


    --output

    COUNT TOTAL
    ---------- ----------
    3 25

    1 Row Selected..
    Vijay.s

  3. #3
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    There is a reply in the Admin forum to this same question that is much more efficient. Check there.

    - Chris

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