Guest User

Untitled

a guest
Feb 18th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. order_id test_id update_count
  2. 10 1 1
  3. 10 1 2
  4. 10 1 3
  5. 11 2 1
  6. 11 5 1
  7. 12 3 1
  8. 12 3 2
  9.  
  10. SELECT LAB_RESULTS.ORDER_ID as 'Order Number'
  11. ,LAB_RESULTS.PATIENT_NO as 'Patient No'
  12. ,Patients.Patient_Name as 'Patient Name'
  13. ,Patients.Age as 'Patient Age'
  14. ,LabTests.TestName as 'Test Name'
  15. ,LAB_RESULTS.RESULT_NUMBER as 'Result'
  16. ,LAB_RESULTS.RESULT_REPORT as 'Text Result'
  17. ,LAB_RESULTS.APPROVED_DATE as 'Approved_Date'
  18. ,LAB_RESULTS.REQ_FORM_NO as 'Request Form Number'
  19. ,LAB_RESULTS.CUSTID as 'Customer Id'
  20. ,Machines.Machine_name as 'Machine Name'
  21. ,LAB_RESULTS.SAMPLE_ID as 'Sample Id'
  22. ,LAB_RESULTS.packageid as 'package id'
  23. ,LAB_RESULTS.GROUPID as 'group id'
  24. ,LAB_RESULTS.EXAMINED_BY as 'Examined By'
  25. ,LAB_RESULTS.EXAMINED_DATE as 'Examined Date'
  26. ,LAB_RESULTS.APPROVED_BY as 'Approved By'
  27. ,LAB_RESULTS.update_count
  28.  
  29.  
  30. FROM LAB_RESULTS
  31.  
  32. inner join patients on LAB_RESULTS.patient_no = Patients.Patient_No
  33. inner join labtests on LabTests.TestId = LAB_RESULTS.TESTID
  34. inner join Machines on Machines.Machine_id = LAB_RESULTS.machine_id
  35.  
  36. where LAB_RESULTS.APPROVED_BY is not null
  37. and LAB_RESULTS.SAMPLE_STATUS = 6
  38. and LAB_RESULTS.update_count in (select max(update_count) from LAB_RESULTS where LAB_RESULTS.SAMPLE_STATUS = 6 and LAB_RESULTS.deptid = 2 )
  39. and LAB_RESULTS.deptid = 2
  40.  
  41. order_id test_id update_count
  42. 10 1 3
  43. 11 2 1
  44. 11 5 1
  45. 12 3 2
  46.  
  47. and LAB_RESULTS.update_count in (select max(update_count) from LAB_RESULTS where LAB_RESULTS.SAMPLE_STATUS = 6 and LAB_RESULTS.deptid = 2 )
Add Comment
Please, Sign In to add comment