Home > database >  The query result display problems
The query result display problems

Time:11-13

Through SQL query results query are

PatientID PatientName CKSJ CKXQ
111 zhang
111 zhang SAN the 2020-07-16 hospital
222 li si
333 fifty
Fifty and 2020-07-16 333 deaths

Want to achieve: if this person CKSJ and CKXQ recorded, there shows only record the data, if the person is only a record, and the record CKSJ and CKXQ is empty, then only show the CKSJ and CKXQ null record is to achieve like this:

PatientID PatientName CKSJ CKXQ
111 zhang SAN the 2020-07-16 hospital
222 li si
Fifty and 2020-07-16 333 deaths

, every brother please draw out a sword to help, I appreciate

CodePudding user response:

 
The select PatientID, PatientName CKSJ, CKXQ
The from (select PatientID, PatientName CKSJ, CKXQ, rn=row_number () over (partition by PatientID order by CKSJ)
The from [table name]) t
Where an rn=1
  • Related