sql - 两个子查询之间的 AND 操作
问题描述
这些是我的表:https ://ibb.co/mqX6wy
我试图找到所有在银行有贷款和账户的客户。
我正在使用 MYSQL(PHP myadmin 客户端)
查询应返回Hayes,Jones,Smith
Select customer_name
from (
SELECT borrower.customer_name
FROM borrower, loan
WHERE borrower.loan_number = loan.loan_number)
AND (SELECT depositor.customer_name
FROM depositor,account
WHERE depositor.account_number = account.account_number)
执行上述查询会抛出:
Error: *#1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MariaDB server version for the right syntax to use
near 'AND (SELECT depositor.customer_name FROM depositor,account WHERE
depositor.acco' at line 1*
解决方案
根据您的表结构,我认为您需要以下查询
Select t1.customer_name from
(
SELECT b.customer_name FROM borrower b inner join
on loan l b.loan_number = l.loan_number) as t1
inner join
(
SELECT depositor.customer_name FROM depositor d inner join account a on
d.account_number = a.account_number
) t2
on t1.customer_name=t2.customer_name
推荐阅读
- reactjs - 盖茨比不显示 Office UI Fabric React 图标
- javascript - 达到最大长度时在多个输入中导航
- python - 如何向数据集添加新列
- c# - 在无限循环中通过 C# 调用的 Python 不返回值
- amazon-s3 - AWS Athena 表数据更新
- python - 为什么 Keras CNN 中每个输入滤波器都有一组参数?
- sql - 在 SQL Server 中计算表中的 Null 并按列名分组
- google-cast - TextTracks not working when VMAP module is enabled
- .net - Opening and closing braces issue
- jquery - 我在 jquery ajax 中有一个脚本并且不工作如何修复错误