My sql query fetches list of bug fix verification for a firmware for e.g. def-456 is a ticket which asks me to test firmware test on a product. def-456 has several sub-tasks where results are being recorded. Results are recorded as :id: abc-123, abc-124, abc-125 etc (as shown in table below). These corresponding id’s have “pass” or “fail” result. I need to calculate two values —->
1. Number of attempts : in following example number of attempts would be 3/5 , there are 3 pass and 2 fail (i.e. pass/pass+fail) , here i can use count() method however don’t know how to append “/5” and
2. 1st attempt success rate : in following example, abc-123 failed however abc-124 passed, abc-125 failed however abc-126 passed and abc-127 passed without any failure, means my success rate is : 1 out 3 (i.e. 1/3), how can I display these values in sql? this is bit tricky and I am not able to find logic for this.
Here is my data for def-456:
value | id|
--------------
fail | abc-123
pass | abc-124
fail | abc-125
pass | abc-126
pass | abc-127
and here is o/p I am trying to display :
id | value | attempts| %for attempts | 1st attempt
----------------------------------------------------
abc-123 fail | 3/5 | 60% | 1/3
abc-124 pass | 3/5 | 60% | 1/3
abc-125 fail | 3/5 | 60% | 1/3
abc-126 pass | 3/5 | 60% | 1/3
abc-127 pass | 3/5 | 60% | 1/3
I believe this is what you need:
SQLFiddle Link