gpt4 book ai didi

php - 数据库复杂 3 路连接查询

转载 作者:行者123 更新时间:2023-11-29 05:32:13 25 4
gpt4 key购买 nike

Tables

您好,我有以下 3 个表,其中包含示例数据

患者:1,DUMMY PT, 78936, 1987-07-18

Custom_fields : 1 , 1 , '血压' , 输入 , '病历'

patient_info:1,1,80/90 blah blah,1


当我非常耐心的页面时,我想要的是获取所有行的“patient_info”,其中 pt_id=patients.patient_id,然后获取 custom_fields.title=cf_id,其中 doctor_id=$id并显示全部。

从上面给出的数据示例来看,它应该是这样的:

患者:DuMMY pt 个人资料页面:-

血压:80/90 等等等等

有什么提示我应该如何将这些表连接在一起吗?

注意:我试过了:

SELECT patient_info.info,custom_fields.title FROM patient_info where patient_info.pt_id='8' and custom_fields.id=patient_info.cf_id and custom_fields.doctor_id = '10'
join patients on patient_info.pt_id=patients.patients_id
join custom_fields on patient_info.cf_id=custom_fields.id

其中 10 和 8 已经给出($vars in php),但我在“join patients on”附近出现错误

最佳答案

试试这个:

SELECT p.info,cf.title 
FROM patient_info p
INNER JOIN patients ps ON p.pt_id=ps.patients_id
INNER JOIN custom_fields cf ON p.cf_id=cf.id
WHERE p.pt_id='8' AND cf.doctor_id = '10'

关于php - 数据库复杂 3 路连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com