select 
     a.spid as 总店商品ID, 
     ... ,
     b.spid as 本店商品ID,
     ... ,
     case 
         when a.spbh != b.spbh   then '编号不同'
         when a.spmch != b.spmch then '名称不同'
         when a.shpgg != b.shpgg then '规格不同'
     end as 商品差异
from 
     zdspkfk a
inner join
     spkfk   b
on 
     a.glid=b.spid
where
     a.spbh != b.spbh or a.spmch != b.spmch or a.shpgg != b.shpgg

解决方案 »

  1.   

    select 
         a.spid as 分店商品ID,a.spbh as 分店商品编号,a.spmch as 分店商品名称,a.shpgg as 分店商品规格,
         
         b.spid as 总店商品ID,b.spbh as 总店商品编号,b.spmch as 总店商品名称,b.shpgg as 总店商品规格,
         case 
             when (a.spbh != b.spbh) and (a.spmch=b.spmch) and (a.shpgg=b.shpgg)  then '编号不同'
             when (a.spmch != b.spmch) and (a.spbh=b.spbh) and (a.shpgg=b.shpgg) then '名称不同'
             when (a.shpgg != b.shpgg) and (a.spbh=b.spbh) and (a.spmch=b.spmch) then '规格不同'
             when (a.spbh !=b.spbh) and (a.spmch !=b.spmch) and (a.shpgg=b.shpgg) then '编号与名称不同'
             when (a.spbh !=b.spbh) and (a.shpgg !=b.shpgg) and (a.spmch=b.spmch) then '编号与规格不同'
             when (a.spbh !=b.spbh) and (a.spmch !=b.spmch) and (a.shpgg !=b.shpgg) then '都不同'
             when (a.spbh = b.spbh) and (a.spmch !=b.spmch) and (a.shpgg !=b.shpgg) then '名称和规格不同'
         end as 商品差异
    from 
         fdspkfk a
    inner join
         spkfk   b
    on 
         a.glid=b.spid
    where
         (a.spbh != b.spbh or a.spmch != b.spmch or a.shpgg != b.shpgg) and a.fdbs='hyjc'这么写为什么不行呢
      

  2.   

    libin_ftsafe(子陌红尘)  方便留一下OICQ 吗?
      

  3.   

    select * from zdspkfk a
    where not exists
    (select 1 from spkfk b where 
         a.glid=b.spid and (a.商品编号<>b.商品编号 or 
             a.商品名称<>b.商品名称 or a.商品规格<>b.商品规格))
    union allselect * from spkfk a
    where not exists
    (select 1 from zdspkfk b where 
         a.glid=b.spid and (a.商品编号<>b.商品编号 or 
             a.商品名称<>b.商品名称 or a.商品规格<>b.商品规格))
      

  4.   

    --改一点
    select a.商品编号, a.商品名称, a.商品规格 from zdspkfk a
    where not exists
    (select 1 from spkfk b where 
         a.glid=b.spid and (a.商品编号<>b.商品编号 or 
             a.商品名称<>b.商品名称 or a.商品规格<>b.商品规格))
    union allselect a.商品编号, a.商品名称, a.商品规格 from spkfk a
    where not exists
    (select 1 from zdspkfk b where 
        b.glid=a.spid and (a.商品编号<>b.商品编号 or 
             a.商品名称<>b.商品名称 or a.商品规格<>b.商品规格))