Results 1 to 2 of 2
  1. #1
    kheneasar is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    6

    Percentages of Column Values in a Query

    Hello,

    I have a simple Access table called "Test," with two columns - Field1 and Field2. The data in the table looks like this.

    Field1 Field2
    1 2
    2 2
    2 2


    2 1
    2 1

    I'm trying to return the percentage of times each data type exists in each column. (ie - In Field1, the number 1 exists 20% and the number 2 exists 80%)

    I found this query and it works great returning one column at a time.

    Select Field1, (Count(Field1)* 100 / (select Count(*) From Test)) as fieldA
    FROM Test
    Group By Field1;

    How would I select both columns? I tried this but it doesn't work.

    Select Field1, (Count(Field1)* 100 / (select Count() From Test)) as fieldA,
    Field2, (Count(Field2) 100 / (select Count(*) From Test)) as fieldB
    FROM Test
    Group By Field1;

    Sorry for posting such a simple question. I haven't done much with Access.
    Thanks,
    Anne

  2. #2
    kheneasar is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    6
    Looks like this did it. Thanks

    select * from (
    SELECT Field1, (Count(Field1)* 100 / (select Count(*) From Test)) as fieldA
    FROM Test
    GROUP BY Field1
    ) a
    left join (
    SELECT Field2, (Count(Field2)* 100 / (select Count(*) From Test)) as fieldB
    FROM Test
    GROUP BY Field2
    ) b on a.Field1 = b.Field2

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-17-2014, 09:16 AM
  2. Replies: 1
    Last Post: 04-30-2014, 01:05 AM
  3. Percentages Query
    By mabrown81 in forum Queries
    Replies: 12
    Last Post: 11-01-2012, 12:50 PM
  4. Replies: 5
    Last Post: 06-13-2012, 07:43 PM
  5. Replies: 2
    Last Post: 11-18-2009, 06:49 PM

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
  •  
Other Forums: Microsoft Office Forums