我正在寻找一个SQL Select语句,当给出CustomerId =' AAAAA'将返回与AAAAA具有相同RegionId的所有行。
由于
CustomerId, RegionId
AAAAA,11111
BBBBB,11111
CCCCC,22222
DDDDD,22222
需要的结果:
AAAAA,11111
BBBBB,11111
答案 0 :(得分:2)
有几种方法可以做到这一点 - 这里有一个in
:
SELECT CustomerId, RegionId
FROM YourTable
WHERE RegionId IN (
SELECT RegionId
FROM YourTable
WHERE CustomerId = 'AAAAA')
答案 1 :(得分:0)
您可以这样选择:
SELECT CustomerId, RegionId
FROM Table
WHERE RegionId = (SELECT RegionId FROM Table WHERE CustomerId = 'AAAAA')