oderID color1 红色1 黄色2 红色2 绿色3 黄色3 绿色4 红色4 黄色查询color既有红色又有黄色的oderID
结果为 1
4 这个怎么写 各位大神

解决方案 »

  1.   

    where color in ('紅色','黃色')
      

  2.   

    --测试数据
    if not object_id(N'Tempdb..#T') is null
    drop table #T
    Go
    Create table #T([oderID] int,[color] nvarchar(22))
    Insert #T
    select 1,N'红色' union all
    select 1,N'黄色' union all
    select 2,N'红色' union all
    select 2,N'绿色' union all
    select 3,N'黄色' union all
    select 3,N'绿色' union all
    select 4,N'红色' union all
    select 4,N'黄色'
    Go
    --测试数据结束
    SELECT a.oderID
      FROM #T a
      JOIN #T b
        ON b.oderID = a.oderID
     WHERE a.color = '红色'
       AND b.color = '黄色';
      

  3.   

    https://bbs.csdn.net/topics/393091848這個你啥時候去處理啊。
      

  4.   

    https://bbs.csdn.net/topics/393091848這個你啥時候去處理啊。时间有点长了……那个楼主结帖率也有点低啊
      

  5.   

    https://bbs.csdn.net/topics/393091848這個你啥時候去處理啊。时间有点长了……那个楼主结帖率也有点低啊助人為樂啊,哥哥。我想了一下午都沒有頭緒。
      

  6.   

    Create table #T([oderID] int,[color] nvarchar(22))
    Insert #T
    select 1,N'红色' union all
    select 1,N'黄色' union all
    select 2,N'红色' union all
    select 2,N'绿色' union all
    select 3,N'黄色' union all
    select 3,N'绿色' union all
    select 4,N'红色' union all
    select 4,N'黄色'select * from #Tselect oderID from #T where color=N'红色'and oderID in (select oderID from #T where color=N'黄色')