Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:32:41+00:00 2026-06-01T23:32:41+00:00

I have a database table with the following kind of data data S_Acc_RowID BU_Customer_Segment

  • 0

I have a database table with the following kind of data data

 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

—————- like 7 million rows

now I want to extract single row for each Acc ID where the conditions are

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**

and the end data I want should be like

  S_Acc_RowID    BU_Customer_Segment   

   1111-00      EB seg
   1111-01      EB Data
   1111-02      (any one of three[PSG seg/ UNattended/channels])

I’m using the following 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 

But it is returning the the data like this

S_Acc_RowID    BU_Customer_Segment   

   1111-00      EB seg
   1111-01      PSG SMB
   1111-01      EB Data
   1111-02      null

I don’t want to display two rows for the ID 1111-01 ..I want only one row with EB

please help me with this ..

Thanks in advance..

Cheers,
Harish

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:32:43+00:00Added an answer on June 1, 2026 at 11:32 pm

    On Oracle, i tried the following and it should work if you convert the oracle specific analytic functions, also i made some changes in the sample data for a better example :

        WITH t AS (
        SELECT '1111-00' AS acc_id, 'PSG SMB' AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-00' AS acc_id, 'SMB'     AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-00' AS acc_id, 'EB Seg'  AS cust_seg,  1 AS pbu FROM dual UNION ALL
        SELECT '1111-01' AS acc_id, 'PSG SMB' AS cust_seg,  1 AS pbu FROM dual UNION ALL
        SELECT '1111-01' AS acc_id, 'SMB'     AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-01' AS acc_id, 'Ex data' AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-02' AS acc_id, 'PSG Seg' AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-02' AS acc_id, 'Unatten' AS cust_seg, -1 AS pbu FROM dual UNION ALL
        SELECT '1111-02' AS acc_id, 'Channels'AS cust_seg, -1 AS pbu FROM dual )
        --
        SELECT acc_id,
               cust_seg
          FROM (SELECT t.*,
                       row_number() OVER(PARTITION BY acc_id ORDER BY CASE WHEN cust_seg LIKE '%EB%' THEN 1 WHEN pbu = 1 THEN 2 ELSE 3 END ) rnk
                  FROM t
                 ORDER BY acc_id, CASE WHEN cust_seg LIKE '%EB%' THEN 1 WHEN pbu = 1 THEN 2 ELSE 3 END)
         WHERE rnk = 1 ;
    
    Result :
    
        ACC_ID                CUST_SEG
        --------------------- ------------------------
        1111-00               EB Seg
        1111-01               PSG SMB
        1111-02               PSG Seg
    

    SQL Server version

        SELECT  *
        FROM    (
                  SELECT  *
                          , rn = ROW_NUMBER() OVER (PARTITION BY S_Acc_RowID ORDER BY CASE WHEN LEFT(a.BU_Customer_Segment, 2) = 'EB' THEN 1 WHEN a.PBU = 1 THEN 2 ELSE 3 END)          
                  FROM    [SiebelAccount Extract] a
                ) q
        WHERE   rn = 1
    

    and testdata

    ;WITH [SiebelAccount Extract] (S_Acc_RowID, BU_Customer_Segment, PBU) AS (
      SELECT * FROM (VALUES 
         ('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)
      ) a (b, c, d)
    )
    SELECT  *
    FROM    (
              SELECT  *
                      , rn = ROW_NUMBER() OVER (PARTITION BY S_Acc_RowID ORDER BY CASE WHEN LEFT(a.BU_Customer_Segment, 2) = 'EB' THEN 1 WHEN a.PBU = 1 THEN 2 ELSE 3 END)          
              FROM    [SiebelAccount Extract] a
            ) q
    WHERE   rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have for example, the following data in my database table... 30 Miles DVD
Say I have a database table like the following: FileID | FileName | FileSize
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------
I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation
I have the following table and sequence in my postgresql-8.4 database: CREATE TABLE complexobjectpy
I have a database with the following table: PATIENT (PATIENT_ID*, MEDICAL_EXAMINATIONS) where the field
I have the following listbox below which binds to a database table of image
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have the following table in my database. Now what I want to find
I have the following table in my postgreSQL 8.3.14 database timestamp status 2012-03-12 19:15:01

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.