I have two database tables containing similar data – one is the amount of work completed by a process, the other is the amount of errors made by that process.
I would like to display the percentage of right first time work.
My query for counting the number of items by process is:
SELECT Counter.Process, count( Counter.Process ) AS count
FROM Counter WHERE (TIME BETWEEN '2012-07-01 00:00:00' AND '2012-07-06 23:59:59')
GROUP BY Counter.Process
ORDER BY count DESC
The above gives me a list similar to:
Process | count
-------------------
Process A | 40
Process B | 32
Process C | 102
Process D | 23
I have a second table with the same fields in it for recording errors, called ‘Errors’.
By using the same query (but changing the table names obviously) I can get a list of processes and errors.
What I want to do is create a PHP web page showing the percentage of errors per process.
My problem is if I create the two queries separately, when I loop through them using a PHP Where loop I don’t know how to make the calculation to show the percentage.
I tried using a UNION between the two SQL queries, but I can’t get it to show the two different count readings against the process.
Ideally, I’d like a way to show the data like this:
Process | Counter.count | Errors.count
Process A 40 2
Process B 32 0
Process C 102 18
Process D 23 8
I would really appreciate any advice/suggestions as to how I can accomplish this – if you need more info on my database tables, please let me know
Thanks for reading
S
You could use a sub-query:
Regards,
Neil.