排除查询SQL Server的某些结果

时间:2015-11-07 19:06:42

标签: sql-server

我有3个表:CLIENT,FEATURE,CLIENT_FEATURE

  • $list_words = array(); function po_fetch_code($dir , $preg = "/_\(('|\")(.*?)('|\")\)/"){ if( is_dir($dir) ){ $list = scandir($dir) ; foreach($list as $l){ if($l == '.' || $l == '..'){ // Do Nothing }else{ po_fetch_code($dir.'/'.$l , $preg) ; } } }else{ $ext = strrchr($dir , '.') ; //if($ext == '.php' || $ext == '.html' || $ext == 'html'){ //$cont = file_get_contents($dir) ; $list = file($dir) ; global $list_words ; foreach($list as $key => $l){ preg_match_all( $preg , $l , $matches ); if(!empty($matches[2])){ foreach($matches[2] as $k=>$m){ //$m = str_replace(array( "\'",'\\' , '"' , "'",'\'' ), '' ,$m) ; //$m = str_replace('\'s', 's' ,$m) ; if(!isset($list_words[$m])){ $list_words[$m]['msgid'] = array($m) ; $list_words[$m]['msgstr'] = array($m) ; $list_words[$m]['reference'] = array() ; } $list_words[$m]['reference'][] = $dir.':'.$key ; } } } // } } } $dir = 'themes/mytheme/' ; po_fetch_code($dir , "/__\(('|\")(.*?)('|\")\)/" ) ; po_fetch_code($dir , "/_e\(('|\")(.*?)('|\")\)/" ) ; :id_client,姓名,姓氏,地址
  • CLIENT:id_feature,feature_txt
  • FEATURE:id_fc,fc_id_client,fc_id_feature

一个客户端可以拥有多个功能。

如果我想看到具有所需1个功能的客户:

FEATURE_CLIENT

没关系,但如果客户端有功能1和20,我想搜索没有功能20的客户端

我测试过:

SELECT 
    [id_client], [name], [surname], [address], [id_feature], 
    [feature_txt], [id_fc], [fc_id_client], [fc_id_feature]
FROM 
    [client]
LEFT JOIN 
    [feature] ON fc_id_client = id_client
WHERE 
    fc_id_feature = 1

但它不起作用。

1 个答案:

答案 0 :(得分:0)

SELECT *
FROM 
    [client]
     INNER JOIN 
    [feature_client] ON 
        client.id_client = feature_client.fc_id_client 
     INNER JOIN 
    [feature] ON 
        feature_client.fc_id_feature = feature.id_feature
WHERE 
    fc_id_feature = 1 AND
    id_client NOT IN
      (
        SELECT fc_id_client
        FROM 
            feature_client 
             INNER JOIN 
            feature ON
                fc_id = id_feature 
        WHERE id_feature = 8
      )