Sql 如何使用下面的代码获取一行中的数据

Sql 如何使用下面的代码获取一行中的数据,sql,postgresql-9.4,Sql,Postgresql 9.4,我想在这里通过保持相应的patient_id iam在1行中获取数据来获取1行中的数据,但如果我通过给出函数的输入参数来执行,则patient_id iam数据将插入ams.ams_trans_integration_events表中,共4行 elsif(\u集成\u类型=34)然后/患者注册/ 我在ams.ams\u trans\u integration\u事件表中插入了4行,如下所示,但我只需要插入1行,这是最后一行 {"refId":504,"patIsActive":true,"pat

我想在这里通过保持相应的patient_id iam在1行中获取数据来获取1行中的数据,但如果我通过给出函数的输入参数来执行,则patient_id iam数据将插入ams.ams_trans_integration_events表中,共4行

elsif(\u集成\u类型=34)然后/患者注册/

我在ams.ams\u trans\u integration\u事件表中插入了4行,如下所示,但我只需要插入1行,这是最后一行

{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"aliya@gmail.com","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"aliya@gmail.com","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":"ITPL","pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"vamsi@gmail.com","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":[{"firstName":"Smitha","lastName":"D","relationship":108,"email":"smitha@gmail.com","homePhone":8895685787,"mobilePhone":9057806789,"area":"Madhura Nagar","pinCode":574768,"city":103826,"state":4152,"address":"4/2/760,Near Minerva School"}]}


{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"aliya@gmail.com","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"aliya@gmail.com","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"vamsi@gmail.com","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":[{"firstName":"Smitha","lastName":"D","relationship":108,"email":"smitha@gmail.com","homePhone":8895685787,"mobilePhone":9057806789,"area":"Madhura Nagar","pinCode":574768,"city":103826,"state":4152,"address":"4/2/760,Near Minerva School"}]}


{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"aliya@gmail.com","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"aliya@gmail.com","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":[{"firstName":"Vamsi","lastName":"G","relationship":91,"email":"vamsi@gmail.com","homePhone":8899002244,"mobilePhone":9894689586,"area":"Shivananda Nagar","pinCode":898359,"city":46486,"state":1714,"address":"9/4/241,Near S.T.Joseph School"}],"patientEmergencyCnt2Details":null}


{"refId":504,"patIsActive":true,"patientCreatedBy":218,"patientMpi":"2000000100000504","patientFirstName":"Aliya","patientMiddleName":null,"patientLastName":"T","patientGender":2,"patientEmail":"aliya@gmail.com","patientDob":"2000-01-02","patientMobile":"8496064235","partnerId":2,"patientMaritalStatus":null,"patientEducationLevel":null,"patientIdentificationMark":null,"patientIsEstimated":false,"patientSalutation":null,"patientBloodGroup":null,"patientMotherTongue":null,"patIdentifierIsactive":true,"patIdentifierDl":null,"patIdentifierUid":null,"patIdentifierPanNo":null,"patIdentifierPassport":null,"patientLanguageIds":null,"patientPersnlDetails":[{"homePhone":884422119900,"mobile1":8496064235,"email":"aliya@gmail.com","workPhone":9086747856,"mobile2":8843756874,"mthdOfComm":1}],"patientMailingAddressDetails":[{"address":"6/2/201,Near Hosur Road","area":null,"pinCode":684869,"city":46246,"state":1710}],"patientEmergencyCnt1Details":null,"patientEmergencyCnt2Details":null}
改变

where   p.patient_id= _patient_id)
致:

改变

where   p.patient_id= _patient_id)
致:


你想得到四行中的哪一行?。实际上我是这样得到四行的如果你得到的是相同的四行,在
SELECT
no之后添加
DISTINCT
,我的所有4行数据都不同,但我只希望最后一行数据出现,所以在where?中定义相应的子句。四行中您希望得到哪一行?。实际上,如果得到的是4行相同的数据,我会得到4行,在
SELECT
no之后添加
DISTINCT
,我的全部4行数据不同,但我只希望最后一行数据出现,所以在where?中定义相应的子句?。。
where   p.patient_id= _patient_id and (select json_agg(patMailingAddressDetails)
            from (
            select cp.pat_cnt_address AS "address",
            cp.pat_cnt_area AS "area",
            cp.pat_cnt_pincode as "pinCode",
            cp.pat_cnt_city as "city",
            cp.pat_cnt_state as "state"
            from  xch.xch_transmasmap_patient_contact pc
            left join  xch.xch_transmas_patient_contact cp  on cp.pat_cnt_id = pc.pat_contact_cnt_id 
            where pc.pat_contact_pat_id = _patient_id and pc.pat_contact_cnt_type_id = 4 and pc.pat_contact_isactive = true
            )patMailingAddressDetails)->>'area' = 'ITPL')