简体   繁体   English

使用连接查询(oracle sql)时如何查看一个表中的所有数据并在另一个表上过滤

[英]How to see all data from one table and filtered on another, when using a join query (oracle sql)

Once I execute split, im hoping to see the following 3 things:一旦我执行拆分,我希望看到以下 3 件事:

  1. The customer record from CUSTOMERS来自 CUSTOMERS 的客户记录
  2. All customer transaction rows from TRANSACTIONS TRANSACTIONS 中的所有客户交易行
  3. Items purchased made during transactions 5 and 6 from PURCHASES在 PURCHASES 的交易 5 和 6 期间购买的物品

My query below gets most of this right except for point 2, as it only returns transactions 5 and 6 instead of the full list.除了第 2 点之外,我在下面的查询获得了大部分权利,因为它只返回事务 5 和 6 而不是完整列表。 What can I change?我能改变什么?

SELECT * FROM customers c
INNER JOIN transactions t ON c.custid = t.custid
INNER JOIN purchaces p ON t.transid = p.transid
WHERE c.customer = 1234 AND t.trans_num IN (5,6)
ORDER BY t.trans_num

You are explicitely filtering for records 5 and 6 in your where statement.您在 where 语句中明确过滤记录 5 和 6。 You can LEFT JOIN the purchases table using that condition.您可以使用该条件 LEFT JOIN 购买表。 You will get all transactions, but the purchases columns will be NULL if they don't belong to transactions 5 or 6.您将获得所有交易,但如果购买列不属于交易 5 或 6,则它们将为 NULL。

SELECT * 
FROM customers c
INNER JOIN transactions t 
  ON c.custid = t.custid
LEFT JOIN purchaces p 
  ON t.transid = p.transid 
  AND t.trans_num IN (5,6)
WHERE c.customer = 1234 
ORDER BY t.trans_num

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Oracle 中一张表的所有数据传输到另一张表? - How to transfer all data from one table to another table in Oracle? SQL:如何使用 MariaDB 中的连接使用来自另一个表的数据更新一个表 - SQL: how to update one table with the data from another using join in MariaDB 从一个表中选择,插入到另一个表中 oracle sql 查询 - select from one table, insert into another table oracle sql query 选择一个表与另一个表的否定以及oracle主表sql查询中的数据 - Select Negation of one table from another along with data in master table sql query for oracle 如何使用插入查询将数据从一个 SQL 表插入另一个表 - How can I insert data from one SQL table to another table using Insert query SQL查询可从一个表中获取所有记录,并在另一个表上进行连接,包括任何其他唯一记录 - SQL Query to get all records from one table and join on another including any additional unique records 在Oracle数据库中查询表/字段时,如何查看查询结果中的表模式? (使用SQuirreL SQL) - When querying tables/fields in Oracle database, how to see table schema in query results? (using SQuirreL SQL) Oracle PL / SQL-如何使用Oracle集合将大量数据从一个表复制到另一个表 - Oracle PL/SQL - How do i copy a large amount of data from one table to another using oracle collections Oracle - SQL 查询根据列值将数据从一个表分装到另一个表? - Oracle - SQL query to bin the data from one table to another based on a column value? Oracle SQL:将所有用户放在一个表中,而不是另一个表中,并加入第三个表 - Oracle SQL: Get all users in one table but not another and join to a third table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM