如何通过使用2个不同的where子句来连接3个表? [英] How can I join 3 tables by using 2 different where clauses for each ?

查看:100
本文介绍了如何通过使用2个不同的where子句来连接3个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有3个表作为帐户,存储和撤销。每个表都有account_no列的共同点。



现在我需要显示帐户表中的account_no,从存储表中获取> 25000的金额列和金额列是从退出表中获得< 50000。



我尝试过:



i已尝试以下查询



i have 3 tables in my database as account,deposite and withdraw. each table have account_no column in common.

now i need to display account_no from account table, amount column which is having >25000 from deposite table and amount column which is having <50000 from withdraw table.

What I have tried:

i have tried the below query

select a.acnt_no,d.deposited_amt,w.balance from acnt a ,deposite d,withdrawl w 
where ((a.acnt_no = d.acnt_no) and (a.acnt_no = w.acnt_no)) 
and (d.deposited_amt>25000 and w.balance>50000)





我也试过内连接和全外连接。所有3个答案都相同



ac.no金额

104 25400.00 66400.00

106 32500.00 75000.00

2500 2500.00 78900.00



但是我有更多的记录符合deposite和withdrawl tables的金额列中的条件。< br $>


i认为结果是基于仅满足两个条件的记录



and i have tried with inner join and full outer join also. all 3 got the same answer that

ac.no amount amount
104 25400.00 66400.00
106 32500.00 75000.00
110 250000.00 78900.00

but i have some more records which are satisfying the condition in both the amounts columns from deposite and withdrawl tables.

i think the result is based on records that are only satisfying the both conditions

推荐答案

尝试:

Try:
SELECT a.acnt_no, d.deposited_amt, w.balance FROM acnt a
JOIN deposite d ON a.acnt_no = d.acnt_no
JOIN withdrawl w ON a.acnt_no = w.acnt_no
WHERE d.deposited_amt > 25000 AND w.balance > 50000

如果这不起作用,您将不得不为所有三个表提供样本表数据,即您希望从该数据中获得的输出,以及从上述查询中获得的输出。

If that doesn't work, you'll have to provide sample table data for all three tables, the output you expect from that data, and the output you get from the above query.


这篇关于如何通过使用2个不同的where子句来连接3个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆