how to SUM and return distinct ?? or Distinct SUM ?? Access 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scorp Scorp
    New Member
    • Mar 2011
    • 40

    how to SUM and return distinct ?? or Distinct SUM ?? Access 2007

    Hello All,
    Am trying to perform this query having the followig table:
    Code:
    -------------------------------
    Color   |   Flag |   qty  |  u.p
    --------------------------------
    red     | 00     |   5    |   6
    red     | 00     |   12   |   2
    blue    | 00     |   13   |   1.8 
    blue    | 01     |    1   |   4
    red     | 02     |   10   |   2 
    red     | 01     |   2    |   2
    blue    | 00     |   6    |   2
    blue    | 02     |   6    |   2
    -----------------------------------
    the criteria is the flag, lets say user chose 00, then the result should be

    Code:
    -------------------------------
    Color   |   Flag | Total
    -------------------------------
    Red     |   00   |   54
    blue    |   00   |   35.4
    ---------------------------
    Where total = SUM(qty * u.p)

    it is causing me a big headache ,
    Any suggestions ???

    Thank you very much in advance.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's no need for a distinct clause, you just need a group by.

    Comment

    • Scorp Scorp
      New Member
      • Mar 2011
      • 40

      #3
      Hey Rabbit

      Can you suggest your sql query plz ??

      Comment

      • Scorp Scorp
        New Member
        • Mar 2011
        • 40

        #4
        Thanks rabit for the hint i think i figured it out :
        Code:
         
        
        SELECT color, flag, sum(qty*u.p) as total
        FROM table
        WHERE flag = "00"
        GROUP BY color;

        Comment

        Working...