mysql - 我有一个已经有左连接搜索的 sql 查询,我需要从另一个表中添加另一个比较,并且只显示过滤结果
问题描述
这是当前查询:(仅列出最后的姓名,首先来自患者表)
选择patients
。id
, IF(CHAR_LENGTH( patients
. last_name
) || CHAR_LENGTH( patients
. first_name
), CONCAT_WS('', patients
. last_name
, ', ', patients
. first_name
), '') FROM patients
LEFT JOIN patient_type
as patient_type1 ON patient_type1
。id
= patients
。patient_type
按 2 订购
我想添加如下内容:
在哪里patient_payment_history
。quoted
> 0
因此我的结果仅显示基于姓名数据比较具有活动非 0 引用的患者(他们的全名以最后一种格式保存在单个列中,并且非 0 引用值保存在这个标记为引用的附加表中。附加表名是 patient_payment_history
我试过这个,我得到了一个引用的列未找到图例:
选择patients
。id
, 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_history
LEFT JOIN patient_type
as patient_type1 ON patient_type1
。id
= patients
。patient_type
和patient_payment_history
。quoted
> 0 按 2 排序
解决方案
推荐阅读
- c++ - 启用 istream operator>> 以接受两个或三个值
- rest - 休息 - 计算价值的 json-ld api 方法?
- java - 在 Eclipse 中编译 Wurst Client 1.12
- python-3.x - 将输出保存在输入文件 python3 的新列中
- adhoc - NS-3,将队列大小添加到 adhoc 网络
- angular - 将第 3 方 JS 插件安装到 Angular 7 中
- php - Can't get bidirectional data from pivot table
- java - Spring boot @TextIndexed 不在 MongoDB 中创建索引
- azure - 当我的 linting 脚本返回错误时,如何让我的 Azure DevOps Pipeline 构建失败?
- linux - 跑步者不健康,将被禁用