简体   繁体   中英

retriveving unrepeated data from mysql

how can i retrieve the date to be displayed once if it is the same for all 4 examintaions so it will display for each examination date will be 4 set of results and passed into JSON

here is my database query and the results I get

SELECT date, tname, value
       FROM examination e, testresults t, examtype ex, testname tn
       WHERE e.patientnhs_no  = '1001001002'
         and e.etype_id       = '1'
         and e.examination_id = t.examination_id
         and e.etype_id       = ex.etype_id
         and t.tname_id       = tn.tname_id

Profiling [ Inline ] [ Edit ] [ Explain SQL ] [ Create PHP Code ] [ Refresh ]

Number of rows:

+ Options

date        tname                  value    
2004-07-05  t3                     6.8
2004-07-05  t4                      29
2004-07-05  tsh                     0.01
2004-07-05  thyroglobulin level     0.5

2005-06-15  t3  5.2
2005-06-15  t4  30
2005-06-15  tsh     0.02
2005-06-15  thyroglobulin level     0.5

and here is the JSON derived from this

[{"test name":"t3","value":"6.8","date":"2004-07-05"},
 {"test name":"t4","value":"29","date":"2004-07-05"},
 {"test name":"tsh","value":"0.01","date":"2004-07-05"},
 {"test name":"thyroglobulin level","value":"0.5","date":"2004-07-05"},
 {"test name":"t3","value":"5.2","date":"2005-06-15"},
 {"test name":"t4","value":"30","date":"2005-06-15"},
 {"test name":"tsh","value":"0.02","date":"2005-06-15"},
 {"test name":"thyroglobulin level","value":"0.5","date":"2005-06-15"}
 ]

but for when I pass this data into the charts repeated data will be a problem to display as xlabel

(If I understand the question correctly) You could get a good start using the group_concat function as follows:

select <patient_id>, date, group_concat( tname, '(', value, ')' separator ',' ) as tests
  where e.patientnhs_no = <patient_id> 
  group by <patient_id>, date;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM