表格患者
表格录入
表格tbl_master
tbl_action
我需要计算不同的时间fibrinolytic_datetime - admission_datetime和table admission field Fibrinolytic是SK。
我试试
SELECT
admission.AN,
admission.HN,
pat_name,
pat_lname,
Fibrinolytic,
DATEDIFF(date_time,(SELECT date_time from tbl_action WHERE tbl_id = "tbl001"))
FROM patient,admission,tbl_action
WHERE admission.HN = patient.HN AND admission.AN = tbl_action.AN
AND Fibrinolytic = "SK" AND tbl_id = "tbl002"
但来自phpmyadmin的回复"Subquery returns more than 1 row"
我想要总计
答案 0 :(得分:0)
从Inner Join
而不是Cross Join
您的子查询返回的值超过1,因为表tbl_action
中有3行对tbl_Id = "tbl001"
SELECT date_time from tbl_action WHERE tbl_id = "tbl001"
您必须通过在此查询的where子句中添加一些唯一ID来唯一标识您要查找的date_time
SELECT date_time from tbl_action WHERE tbl_id = "tbl001" and AN ="AN001"
修改强>
SELECT
admission.AN,
admission.HN,
pat_name,
pat_lname,
Fibrinolytic,
DATEDIFF(date_time,(SELECT date_time from tbl_action WHERE tbl_id = "tbl001" and AN ="AN001"))
FROM patient
inner join admission on admission.HN = patient.HN
inner join tbl_action on admission.AN = tbl_action.AN
WHERE admission.Fibrinolytic = "SK" AND tbl_action.tbl_id = "tbl002"