1

For the table "Test":

+---------+------+-------+
| Section | Test | Count |
+---------+------+-------+
| A       | T1   |    20 |
| A       | T2   |    10 |
| A       | T3   |    15 |
| A       | T4   |    30 |
| B       | T1   |    10 |
| B       | T2   |    40 |
| B       | T3   |    25 |
| B       | T4   |    30 |
+---------+------+-------+

I want to calculate the percentage of the count for each test group by the section (example: for the first calculation: (20*100)/(20+10+15+30)). The resulting table should be as below.

+---------+------+-------+------------+
| Section | Test | Count | Percentage |
+---------+------+-------+------------+
| A       | T1   |    20 | 26.6       |
| A       | T2   |    10 | 13.3       |
| A       | T3   |    15 | 20         |
| A       | T4   |    30 | 40         |
| B       | T1   |    10 | 9.5        |
| B       | T2   |    40 | 38.1       |
| B       | T3   |    25 | 23.8       |
| B       | T4   |    30 | 28.6       |
+---------+------+-------+------------+

Please let me know of any good solution.

Taryn
  • 242,637
  • 56
  • 362
  • 405
Sam
  • 47
  • 1
  • 6
  • Have you tried writing a query to get the result that you want? You should really include your attempts and explain why they didn't work. – Taryn Dec 24 '14 at 13:45
  • 2
    @bluefeet . . . "Too broad" is not a reason to close this question. – Gordon Linoff Dec 24 '14 at 13:46
  • 1
    @GordonLinoff Yes, it is. No attempts shown on solving the problem. There are many ways to solve this, users don't like write the code for me questions. – Taryn Dec 24 '14 at 13:47
  • @bluefeet . . . That is definitely not my interpretation of "too broad", and I don't think there is a close reason for that purpose. Do you want to suggest one on the meta site? – Gordon Linoff Dec 24 '14 at 13:48
  • 1
    @GordonLinoff This has been discussed multiple times on Meta. It comes down to showing some sort of attempt at solving the problem. At this point, this could be answered any number of ways making it too broad. – Taryn Dec 24 '14 at 13:48
  • 1
    Related Meta discussion: http://meta.stackoverflow.com/questions/270903/how-to-reduce-and-quickly-close-questions-that-are-merely-requirements?lq=1 – Michael McGriff Dec 24 '14 at 13:59
  • 1
    @SAM there are several ways to solve this. One method involves generating a set of data that sums the count by section, and then joins this back to all your data so you can do the math easily. Another way involves using a windowed set so you can avoid the subquery. Both have their merits. Have you tried anything? if so can you add it to your question please. – xQbert Dec 24 '14 at 14:10

0 Answers0