All,
Via much research, I have managed to get the following query to work, however I don't fully understand what it's doing. I now need to adapt it a little, hence need to understand it more thoroughly.
The query looks in several tables to provide a list of results with one row per group of results as opposed to having one row per result (which would have too much duplication of information)
The query is:-
SELECT od_date, tbl_order.od_id, tbl_order_item.od_item_id, pd_code, item_code, pd_name, >cust, pd_type, tbl_order_item.od_item_id, tbl_order_item.test_suite_name,
MAX( IF( tbl_lab_item.test_name = 'Test 1', tbl_lab_item.test_result, NULL ) ) AS TEST1,
MAX( IF( tbl_lab_item.test_name = 'Test 2', tbl_lab_item.test_result, NULL ) ) AS TEST2,
MAX( IF( tbl_lab_item.test_name = 'Test 3', tbl_lab_item.test_result, NULL ) ) AS TEST3,
MAX( IF( tbl_lab_item.test_name = 'Test 4', tbl_lab_item.test_result, NULL ) ) AS TEST4,
MAX( IF( tbl_lab_item.test_name = 'Test 5', tbl_lab_item.test_result, NULL ) ) AS TEST5,
MAX( IF( tbl_lab_item.test_name = 'Test 6', tbl_lab_item.test_result, NULL ) ) AS TEST6
FROM tbl_item
INNER JOIN tbl_item ON tbl_lab_item.od_item_id = tbl_item.od_item_id
INNER JOIN tbl_order ON tbl_order.od_id = tbl_item.od_id
WHERE tbl_order.od_date LIKE '%$orderDate%'
AND customer_id = '%custID%'
GROUP BY tbl_lab_item.od_item_id
This give me the following output:-
Order Date | Order ID | Item Id | <snip - other columns> | TEST1 | TEST2 | TEST 3 ...etc
09/09/2013 | 2 | 1 | | 10 | 20 | 30 ...etc
What I want to do now is display any result which is less than 50 as '< 50' rather than have the actual number displayed. Ditto for '>100'.
I'm not sure how to add this logic into the above query, or even whether it is possible.
Any help you can offer would be greatly appreciated.
Many thanks, Jason