本人写了以下语句
select distinct jh from ytk_tc 
except 
select distinct jh from ytk_yxtx 
求差集通过不了,报错说Msg 156, Level 15, State 1, Line 3
在关键字 'except' 附近有语法错误。select distinct jh from ytk_tc和
select distinct jh from ytk_yxtx 单独执行都没问题?

解决方案 »

  1.   

    select distinct jh from ytk_tc,ytk_yxtx
    except不能这样用吧
      

  2.   

    except 
    这个函数不能在sql语句中使用...
      

  3.   

    select distinct jh from ytk_tc 
    union
    select distinct jh from ytk_yxtx
      

  4.   

    select distinct jh from ytk_tc 
    union all --不合并连接的重复项用
    select distinct jh from ytk_yxtx
      

  5.   

    select distinct jh from ytk_tc 
    where jh not in (
    select distinct jh from ytk_yxtx 
    )or:select distinct jh from ytk_tc 
    where not exists (
    select 1 from ytk_yxtx  where jh=ytk_tc.jh
    )
    except 不是sql server数据库的关键字是sql  Analysis Services 的关键字
      

  6.   

    Except
    查找两个集合之间不同的项,可以选择保留重复项。语法
    Except(«Set1», «Set2»[, ALL])注释
    在查找不同的项之前先消除两个集合中的重复项。可选的 ALL 标志保留重复项。清除 «Set1» 中的匹配重复项并保留非匹配重复项。示例Except({Canada, [British Columbia], Mexico, [British Columbia], USA, Washington}, {Canada, Mexico, California})返回{[British Columbia], USA, Washington}示例Except({Canada, [British Columbia], Mexico, [British Columbia], USA, Washington}, {Canada, Mexico, California}, ALL)返回{[British Columbia], [British Columbia], USA, Washington}.
      

  7.   

    select id from 表A where 列A=1
    except
    select id from 表A where 列A=2
      

  8.   

    except好像不支持select语句
    select distinct jh from ytk_tc where jh not in (select distinct jh from ytk_yxtx)
      

  9.   

    用以下语句替代:select distinct jh from ytk_tc 
    where jh not in (
    select distinct jh from ytk_yxtx 
    )
    union all
    select distinct jh from ytk_yxtx 
    where jh not in (
    select distinct jh from ytk_tc
    )
      

  10.   

    强烈建议微软导入EXCEPT语法,一个差集运算搞的这么麻烦。
      

  11.   

    gc_ding(E.T)  加union all与差集的定义不符合了,应该不必union all
      

  12.   

    not in 就是差集了,没有麻烦不麻烦这一说,不习惯而已
      

  13.   

    gc_ding(E.T)  加union all与差集的定义不符合了,应该不必union all
    -----------------------------------------------------
    select distinct jh from ytk_tc 
    where jh not in (
    select distinct jh from ytk_yxtx 
    )
    只表示ytk_tc有,ytk_yxtx没有的记录
    不能表示ytk_tc没有,ytk_yxtx有的记录