[英]Pl / Sql select statement?
There is an databese table; 有一个数据库表;
> == 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
How can I select the customers that have at least one of the types of {1 and 5} ? 如何选择至少具有{1和5}类型之一的客户?
If you want customers with accounts of type 1 OR 5: 如果您希望客户使用1或5型帐户:
SELECT * FROM customers WHERE account_type IN (1, 5);
[EDIT] If you want customers with accounts of type 1 AND 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
你的意思是这样吗?
select * from table where account_type IN (1,5);
Here is one way to do it: 这是一种实现方法:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.