I have three tables: - - Order (gives me the date of the order) - Position of the order position (gives me the opportunity to associate the result of the activity with the date of the order) - Activity Item (gives me the result of the activity)
I am trying to display the results on a graph and can successfully create an array for all the results less <= 50 as Passed using the following query: -
SELECT
YEAR( od_date ) AS Year,
MONTH( od_date ) AS Month,
test_name,
pd_name,
COUNT( test_result ) AS Passed
FROM tbl_lab_item
INNER JOIN tbl_order_item
ON tbl_order_item.od_item_id = tbl_lab_item.od_item_id
INNER JOIN tbl_order
ON tbl_order.od_id = tbl_order_item.od_id
WHERE tbl_order.od_date >= DATE_SUB(now(), INTERVAL 12 MONTH)
AND test_name = 'Test'
AND pd_name = 'Product'
AND test_result <= 50
AND od_customer_id = '4'
GROUP BY test_name, YEAR(od_date), MONTH(od_date)ASC
I can do this for unsuccessful results using the same query, but with Count (test_result) AS Error in Select and changing WHERE criteria to> 50.
I would like to do two more things in one query, if at all possible.
Firstly, I would like to combine the pass and the failure in the same request in order to get the month, the number of passes, the number of failures.
-, , , , , , , . UNION, , Null as Failed Pass , ?
, mysql?, , .
, ?