我只想在Credit中的所有行都已填充时选择客户端。从表中,我只想看到客户端1、客户端3、客户端4和客户端5的行。
我试过这个:
SELECT *
FROM table
WHERE EXISTS (SELECT client FROM table WHERE [CREDIT] = 'cred')
但不起作用。。。
谢谢!
客户 | |
---|---|
1 | CRED |
1 | CRED |
1 | CRED |
1 | CRED |
1 | CRED |
2 | |
2 | CRED |
2 | CRED |
3 | CRED |
3 | CRED |
3 | CRED |
3 | CRED |
4 | CRED |
4 | CRED |
5 | CRED |
6 | |
6 | |
6 | |
6 | CRED |
6 | CRED |
您需要一个self-(antisemi(连接:
SELECT t.*
FROM table t
WHERE NOT EXISTS (SELECT 1
FROM table t2
WHERE t1.client = t2.client
AND t2.credit IS NULL)
SELECT client, count(credit) FROM t
group by client
having count(client) = sum(case when credit is null then 0 else 1 end)