Count Distinct in access while totaling up values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • singhals
    New Member
    • Jun 2010
    • 9

    Count Distinct in access while totaling up values

    I have two columns of data something like this:

    A 11
    A 12
    B 14
    C 15
    C 42
    C 94
    D 12

    I want my query to result in a distinct count of data in column 1 and sum of column 2. So result should be something like:
    4 200

    I think one way could be to first run a query to group by column 1 and sum of column 2 and then on resultant table run a count of column 1.

    However I want to explore if there is a way within ms-acces of skipping above make a single query.

    Tx,
    Sagar
    Attached Files
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    This is SQL using subqueris and it works for me.
    Code:
    SELECT Count(A) AS CountOfTxt, Sum(B) AS SumOfNo
    FROM (SELECT t.Txt as A,Sum(t.No) as B
    FROM tbl_Demo as t
    GROUP BY t.Txt);
    Where txt is the text column and No is the number column.

    If you have any questions please ask.

    Comment

    Working...