Home > Blockchain >  Sql determine rows that dont have value
Sql determine rows that dont have value

Time:05-07

I have a table that returns results like

abc   yes
abc   no
cdef  no
cdef  no
cdef  no
xyz   yes
xyz   no
xyz   no

sample query

with abc as(
select 'abc' as b , 'yes' as a
union all
select  'abc', 'no'
 
union all
select  'cdef', 'no'
union all
select  'xyz', 'no'
union all
select  'xyz', 'no'
)
 select * from abc

I want to return results that show accounts and indicate yes if they have a yes in any row and no if they dont so should look like this

abc yes
cdf no
xyz yes.

How can I do this?

CodePudding user response:

A simple aggregation should do the trick.

Select Col1
      ,Col2 = max(Col2)
 From  YourTable
 Group By Col1
  • Related