曾几何时,我的SQL还是挂了科了,现如今...... 哎
id(种子标识列) productId(商品ID) kindId(商品类型) siteId(店铺ID)
                 1                1                   1
                 2                1                   1
                 1                2                   1
                 2                2                   1      
                 3                2                   1                 1                1                   2
                 1                2                   2
                 2                2                   2     
                 
                 1                1                   3
siteId=1 是基础店铺,也就是标准. 
我想查出 不同商店(siteId=2 ,=3等等)对应基础店铺 的 存在的商品类型 不存在的 商品.
好吧 其实我也说不明白.也就是 这么个结果
当siteId = 2 的时候,查出来的应该是
id(种子标识列) productId(商品ID) kindId(商品类型) 
                     2                   1        
                     3                   2    
                     
当siteId = 3 的时候,查出来的应该是
id(种子标识列) productId(商品ID) kindId(商品类型)
                     2                   1           
                      
                               

解决方案 »

  1.   

    Create table #(id int identity(1,1),productId int,kindId int,siteId int)   insert into #
    select 1, 1 ,1
    union all select   2, 1, 1
    union all select   1 ,2, 1
    union all select   2, 2 ,1   
    union all select  3, 2, 1
    union all select   1, 1, 2
    union all select   1 ,2, 2
    union all select   2, 2 ,2     
    union all select  1 ,1 ,3
    --商店(siteId=2)对应基础店铺 的 不存在的商品类型.
    select productId,kindId
    from # A
    where not exists
    (
    select 1 from # where productId = A.productId and kindId = A.kindId and siteId = 2
    )   
    and siteId = 1
    group by productId,kindIddrop table #
    我理解的,最好把需求说清楚点
      

  2.   

    其实我想说的是这么一个意思.
    店铺1(siteId=1)是一个标准,他有所有的 类型(kindId) 的商品(productId)
    当我想查询siteId=2,的货物缺少情况的时候,由于siteId=2,他有kindid=1,=2的商品,但是不全.所以我想查出缺省的商品,那么我就会出现这么一个结果集:
    productId(商品ID) kindId(商品类型)  
         2                 1   
         3                 2   
    他缺少 种类(kindid=1)下的商品(productid=2) 和 种类(kindid=2)下的商品(productid=3)
    当我想查询siteId=3是,由于他有自己的特色,他不卖kindid=2的商品,所以当查询他是缺省商品的时候,会出现的结果集:
    productId(商品ID) kindId(商品类型)  
         2                 1   嗯,清楚了!