Sql server 2005 在MicrosoftSQLServer2005中,如何读取第1列中的随机行和第2列中的随机行相等?

Sql server 2005 在MicrosoftSQLServer2005中,如何读取第1列中的随机行和第2列中的随机行相等?,sql-server-2005,Sql Server 2005,我有三个专栏 列标记1 柱过渡 列标记2 好吧,这并不漂亮,但我认为它符合你的要求 cte的原因是为了使sql更易读 with t1a as (select * from tablea a where a.mark1 = 1 and a.transition = 'a'), t2b as (select * from tablea a where a.mark1 = 2 and a.transition = 'b') selec

我有三个专栏

  • 列标记1
  • 柱过渡
  • 列标记2

  • 好吧,这并不漂亮,但我认为它符合你的要求

    cte的原因是为了使sql更易读

    with t1a as
        (select * 
        from tablea a
        where a.mark1 = 1
        and a.transition = 'a'),
    t2b as
        (select * 
        from tablea a
        where a.mark1 = 2
        and a.transition = 'b')
    select t1a.mark2 
    from t1a
    where mark2 in (select mark1 from t2b)
    union 
    select t2b.mark2
    from t2b
    
    希望我没有误解你的要求

    2
    3
    
    with t1a as
        (select * 
        from tablea a
        where a.mark1 = 1
        and a.transition = 'a'),
    t2b as
        (select * 
        from tablea a
        where a.mark1 = 2
        and a.transition = 'b')
    select t1a.mark2 
    from t1a
    where mark2 in (select mark1 from t2b)
    union 
    select t2b.mark2
    from t2b