Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding this query further
    primarykey
    data
    text
    <p>All,</p> <p>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.</p> <p>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)</p> <p>The query is:-</p> <pre><code>SELECT od_date, tbl_order.od_id, tbl_order_item.od_item_id, pd_code, item_code, pd_name, &gt;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 </code></pre> <p>This give me the following output:-</p> <pre><code>Order Date | Order ID | Item Id | &lt;snip - other columns&gt; | TEST1 | TEST2 | TEST 3 ...etc 09/09/2013 | 2 | 1 | | 10 | 20 | 30 ...etc </code></pre> <p>What I want to do now is display any result which is less than 50 as '&lt; 50' rather than have the actual number displayed. Ditto for '>100'.</p> <p>I'm not sure how to add this logic into the above query, or even whether it is possible.</p> <p>Any help you can offer would be greatly appreciated.</p> <p>Many thanks, Jason</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload