TSQL Comparing two Sets

后端 未结 6 2116
野的像风
野的像风 2021-01-18 03:58

When two sets are given

s1 ={ a,b,c,d} s2={b,c,d,a}

(i.e)

TableA

Item
a
b
c
d

TableB

Item
b
c
d
a

How to write Sql quer

6条回答
  •  温柔的废话
    2021-01-18 04:54

    My monstrocity:

    ;with SetA as
    (select 'a' c union
    select 'b' union
    select 'c') 
    , SetB as 
    (select 'b' c union
    select 'c' union
    select 'a' union 
    select 'd'
    ) 
    select case (select count(*) from (
    select * from SetA except select * from SetB
    union 
    select * from SetB except select * from SetA
    )t)
    when 0 then 'Equal' else 'NotEqual' end 'Equality'
    

提交回复
热议问题