Jump to content

sql help


bandababu

Recommended Posts

data ila undi

column A           column B

Adam                  Y

Bob                    N

Tom                    Y

Hanson               N

 

Column A ni 2 separate columns kinda split cheyyali based on flag condition in column B. kani nulls kooda vasthunnayi split chesinappudu

 

select case when column B = 'Y' then column A end as result1,

case when column B = 'N' then column A end as result2 

from table

 

ee query execute chesinappudu output ila vachindi

 

result A       result B

Tom              Null

Adam           Null

Null              Bob

Null             Hanson

 

But naku output ila ravali

 

result A   result B

tom          Bob

Adam       Hanson

 

 

 

Link to comment
Share on other sites

7 hours ago, bandababu said:

data ila undi

column A           column B

Adam                  Y

Bob                    N

Tom                    Y

Hanson               N

 

Column A ni 2 separate columns kinda split cheyyali based on flag condition in column B. kani nulls kooda vasthunnayi split chesinappudu

 

select case when column B = 'Y' then column A end as result1,

case when column B = 'N' then column A end as result2 

from table

 

ee query execute chesinappudu output ila vachindi

 

result A       result B

Tom              Null

Adam           Null

Null              Bob

Null             Hanson

 

But naku output ila ravali

 

result A   result B

tom          Bob

Adam       Hanson

 

 

 

 

Y & N cominations more than 2 vunte emi ravali output?

Link to comment
Share on other sites

7 hours ago, bandababu said:

data ila undi

column A           column B

Adam                  Y

Bob                    N

Tom                    Y

Hanson               N

 

Column A ni 2 separate columns kinda split cheyyali based on flag condition in column B. kani nulls kooda vasthunnayi split chesinappudu

 

select case when column B = 'Y' then column A end as result1,

case when column B = 'N' then column A end as result2 

from table

 

ee query execute chesinappudu output ila vachindi

 

result A       result B

Tom              Null

Adam           Null

Null              Bob

Null             Hanson

 

But naku output ila ravali

 

result A   result B

tom          Bob

Adam       Hanson

 

 

 

Result lo how TOM and BOB are related? Or ADAM and HANSON.. emanna relation undha or rendu columns lo random ga ravacha data .. i mean there is no relation between col A and col B aa?

Link to comment
Share on other sites

32 minutes ago, former said:

Y & N cominations more than 2 vunte emi ravali output?

same thing

oka column Y values, second column lo N values undali without any nulls

Link to comment
Share on other sites

30 minutes ago, mettastar said:

Result lo how TOM and BOB are related? Or ADAM and HANSON.. emanna relation undha or rendu columns lo random ga ravacha data .. i mean there is no relation between col A and col B aa?

column A are person names

column B is a flag column that tells whether person is a parent or a child, If column B = 'Y' then he is a parent . If column B = 'N' then he is a child.

so parent, child two columns laga ravali

Link to comment
Share on other sites

29 minutes ago, bandababu said:

column A are person names

column B is a flag column that tells whether person is a parent or a child, If column B = 'Y' then he is a parent . If column B = 'N' then he is a child.

so parent, child two columns laga ravali

TOM is BOB parent aa?

Link to comment
Share on other sites

@bandababu

idi oka saari try cheii... srry naa sys lo SQL ledu..

;With A as
(
Select ColA, rn = ROW_NUMBER() OVER (Partition by ColB order by ColA)
From Table
Where ColB = 'N'
), B as
(
Select ColA, rn = ROW_NUMBER() OVER (Partition by ColB order by ColA)
From Table
Where ColB = 'Y'
)
Select res1 = A.ColA, res2 = B.ColA
From A inner join B
on A.rn = B.rn

Link to comment
Share on other sites

12 hours ago, bandababu said:

data ila undi

column A           column B

Adam                  Y

Bob                    N

Tom                    Y

Hanson               N

 

Column A ni 2 separate columns kinda split cheyyali based on flag condition in column B. kani nulls kooda vasthunnayi split chesinappudu

 

select case when column B = 'Y' then column A end as result1,

case when column B = 'N' then column A end as result2 

from table

 

ee query execute chesinappudu output ila vachindi

 

result A       result B

Tom              Null

Adam           Null

Null              Bob

Null             Hanson

 

But naku output ila ravali

 

result A   result B

tom          Bob

Adam       Hanson

 

 

 

Tom ki Bob ee enduku ravali? Hanson enduku rakudadu..What relation do they have ? Koncham requirement clear ga seppu

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...