Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Malaysia
    Posts
    1

    Post Unanswered: Select DISTINCT and SUM

    Hi everybody. Thanks for reading my message. Below is the table structure and sample data.

    CODE | AMOUNT
    00001 | 1000
    00002 | 1300
    00001 | 1000
    00003 | 5000
    00001 | 1000

    I would like to know how i can select distinct and sum at the same time from the above sample data ? I am using FireBird and using "SELECT DISTINCT CODE,SUM(AMOUNT) FROM TABLE" as the query but it is not accepted. Thanks in advance. Best regards.

  2. #2
    Join Date
    Nov 2003
    Location
    Jakarta, Indonesia
    Posts
    32
    use group by, but i dont know if firebird support it

  3. #3
    Join Date
    Nov 2003
    Location
    Bangalore,India
    Posts
    51

    Re: Select DISTINCT and SUM

    Originally posted by markytham
    Hi everybody. Thanks for reading my message. Below is the table structure and sample data.

    CODE | AMOUNT
    00001 | 1000
    00002 | 1300
    00001 | 1000
    00003 | 5000
    00001 | 1000

    I would like to know how i can select distinct and sum at the same time from the above sample data ? I am using FireBird and using "SELECT DISTINCT CODE,SUM(AMOUNT) FROM TABLE" as the query but it is not accepted. Thanks in advance. Best regards.
    Its possible like this ....
    select 'this is workaround',(select distinct...),(select sum()) from sometable

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i haven't used firebird but it looks like you want grouping...

    select code, sum(amount)
    from yourtable
    group by code


    rudy
    http://r937.com/

  5. #5
    Join Date
    Nov 2003
    Location
    Jakarta, Indonesia
    Posts
    32
    And you can also use nested select

    select distinct code, (select sum(amount) from yourtahle as nestedtable where nestedtable.code=yourtable.code) from yourtable

Posting Permissions

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