我有一个包含以下数据数据的数据库表
S_Acc_RowID BU_Customer_Segment PBU
1111-00 PSG SMB -1
1111-00 SMB -1
1111-00 EB Seg 1
1111-01 PSG SMB 1
1111-01 SMB -1
1111-01 EB data -1
1111-02 PSG Seg -1
1111-02 Unattended -1
1111-02 Channels -1
---------------- 像 700 万行
现在我想为条件所在的每个 Acc ID 提取单行
1) if the **Acc ID** is having 'EB --' in **CustSeg** then select that **CustSeg** value
2) if **Acc Id** is not having any 'EB -- ' in CustSeg then select **CustSeg** where **PBU** = 1
3) if the both above failed take any one value of the **CustSeg**
我想要的最终数据应该是
S_Acc_RowID BU_Customer_Segment
1111-00 EB seg
1111-01 EB Data
1111-02 (any one of three[PSG seg/ UNattended/channels])
我正在使用以下查询
select
distinct(A.[S_Acc_RowID]) as [Account_RowID],
[EB Customer Segment] =
case
when LEFT(A.[BU_Customer_Segment],2) = 'EB' then A.[BU_Customer_Segment]
when LEFT(A.[BU_Customer_Segment],2) != 'EB' then
(select B.[BU_Customer_Segment] from
dbo.[SiebelAccount Extract] B
where A.[S_Acc_RowID]=B.[S_Acc_RowID]
and [PBU] = 1)
else A.[BU_Customer_Segment]
end,
A.[S_Acc_AMID2#] as [AMID Level 2(Acc)],
A.[S_Acc_Login_P] as [Sales Team(Acc)],
A.[S_Acc_Org_P] as [Country_det],
A.[Customer AMID Level 2 Name(ACC)]
from dbo.[SiebelAccount Extract] A
但它正在返回这样的数据
S_Acc_RowID BU_Customer_Segment
1111-00 EB seg
1111-01 PSG SMB
1111-01 EB Data
1111-02 null
我不想为 ID 1111-01 显示两行 ..我只想要 EB 的一行
请在这件事上给予我帮助 ..
提前致谢..
干杯,
哈里什