首页 > 解决方案 > 我有一个已经有左连接搜索的 sql 查询,我需要从另一个表中添加另一个比较,并且只显示过滤结果

问题描述

这是当前查询:(仅列出最后的姓名,首先来自患者表)

选择patientsid, IF(CHAR_LENGTH( patients. last_name) || CHAR_LENGTH( patients. first_name), CONCAT_WS('', patients. last_name, ', ', patients. first_name), '') FROM patientsLEFT JOIN patient_typeas patient_type1 ON patient_type1id= patientspatient_type按 2 订购

我想添加如下内容:

在哪里patient_payment_historyquoted> 0

因此我的结果仅显示基于姓名数据比较具有活动非 0 引用的患者(他们的全名以最后一种格式保存在单个列中,并且非 0 引用值保存在这个标记为引用的附加表中。附加表名是 patient_payment_history

我试过这个,我得到了一个引用的列未找到图例:

选择patientsid, patient_payment_history. quoted, IF(CHAR_LENGTH( patients. last_name) || CHAR_LENGTH( patients. first_name), CONCAT_WS('', patients. last_name, ', ', patients. first_name), '') FROM patients patient_payment_historyLEFT JOIN patient_typeas patient_type1 ON patient_type1id= patientspatient_typepatient_payment_historyquoted> 0 按 2 排序

标签: mysqlselectphpmyadminleft-join

解决方案


推荐阅读