簡體   English   中英

pl / sql選擇語句?

[英]Pl / Sql select statement?

有一個數據庫表;

> == 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}類型之一的客戶?

如果您希望客戶使用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

你的意思是這樣嗎?

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

這是一種實現方法:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM