Pl / Sql选择语句?

时间:2011-12-08 09:01:51

标签: sql oracle plsql

有一个数据库表;

> == id || customer_number || account_type || balance
> == 1   - 123456          -  1              - 100
> == 2   - 123457          -  1              - 200
> == 3   - 123456          -  3              - 200
> == 4   - 123456          -  4              - 220
> == 5   - 123456          -  5              - 250
> == 6   - 123457          -  2              - 200

如何选择至少具有{1和5}类型之一的客户?

3 个答案:

答案 0 :(得分:7)

如果您希望客户的帐户类型为1或5:

SELECT * FROM customers WHERE account_type IN (1, 5);

[编辑] 如果您希望客户的帐户类型为1和5:

SELECT DISTINCT(c1.customer_number)
FROM customers c1, customers c2
WHERE c1.customer_number = c2.customer_number
    AND c1.account_type = 1
    AND c2.account_type = 5

答案 1 :(得分:2)

你的意思是这样吗?

select * from table where account_type IN (1,5); 

答案 2 :(得分:0)

这是一种方法:

SELECT customer_number 
FROM customers c 
WHERE EXISTS 
    (
    SELECT 1 FROM customers c1 WHERE c1.account_type = 1 AND c1.customer_number = c.customer_number)
    ) 
AND c.account_type = 5