ho una tabella del database con il seguente tipo di dati di datiquery SQL per recuperare la singola riga di dati con i valori desiderati per le colonne
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
---------- ------ come 7 milioni di righe
ora voglio estrarre singola riga per ogni ID Acc dove le condizioni sono
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**
ei dati fine voglio dovrebbe essere come
S_Acc_RowID BU_Customer_Segment
1111-00 EB seg
1111-01 EB Data
1111-02 (any one of three[PSG seg/ UNattended/channels])
Sto utilizzando la seguente query
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
Ma è restituire i dati in questo modo
S_Acc_RowID BU_Customer_Segment
1111-00 EB seg
1111-01 PSG SMB
1111-01 EB Data
1111-02 null
Non voglio visualizzare due righe per l'ID 1111-01 .. Voglio una sola riga con EB
please help me con questo ..
Grazie in anticipo ..
Acclamazioni,
Harish
+1 SQL Server si comporta quasi lo stesso. Ho una query funzionante, quasi identica, ma mi hai battuto di un minuto :). –
Ciao, grazie per la risposta. Ma voglio il risultato per 1111-01 come 'EB%', non come PSG .. E ho anche 7 milioni di righe nella mia tabella, quindi penso di avere una semplice query per eseguirlo velocemente .. – harry
Grazie Lieven =) – mcha