【发布时间】:2012-04-04 06:13:14
【问题描述】:
我在名为 MY_ATTRIBUTES 的 Oracle 表中有以下数据示例:
Date Emp_No Attribute
-----------------------------------------------------
01/04/2012 1234567 APPLE
01/04/2012 1234567 ORANGE
01/04/2012 1234567 PINEAPPLE
01/04/2012 1234567 BANANA
01/04/2012 8888888 APPLE
01/04/2012 8888888 ORANGE
01/04/2012 2222222 APPLE
01/04/2012 2222222 ORANGE
01/04/2012 2222222 PINEAPPLE
根据上面的示例数据,我只需要返回仅使用 Date 和 Emp_No 的不同记录,其中这些记录包含同时具有“APPLE”和“PINEAPPLE”属性的数据
所以根据这个标准,我希望只有以下两条结果记录,即:
01/04/2012 1234567
01/04/2012 2222222
我希望编写一个 Oracle SQL 查询,它将根据所描述的条件返回此结果集。
我还应该指出,我需要将此 SQL 查询用作主 SELECT 的子查询。
【问题讨论】:
-
您的问题包含答案...当您区分记录时使用 distinct 函数...例如 Select distinct from table where.....
-
明白你在说什么,但我不知道如何提取属性为 APPLE 和 PINEAPPLE 的记录。
-
你可以使用 IN 函数..或 UNION..Select distinct date,emp_no from (select * from table where attribute = apple union select * from table where attribute = apple)....跨度>