如果链接表不包含特定值,则返回Count

时间:2018-10-15 12:56:43

标签: sql-server tsql

我正在链接Microsoft SQL Server中的两个表。一个表包含文档,另一个表包含事件状态,我需要指定一个条件。

在文档表上,我正在查看与事件链接的文档代码,例如<% btn1.Text = "Text for original button"; %> 371268-INV-1。每个事件应有2个文档。

我需要返回“事件”表中的状态为已批准但没有包含批准的文档代码的值/计数。

我开始使用:

371268-INV-1-APPROVED

2 个答案:

答案 0 :(得分:0)

这将获取所有已批准的事件,这些事件在documents表中没有2条记录。我认为这将为您提供所需的结果。

{
  "from" : 0, "size" : 60,
  "_source" : ["title", "description"],
  "query" :{
  "bool" : {
    "must" : [
      {
        "term" : {
          "user.id" : {
            "value" : 4,
            "boost" : 1.0
          }
        }
      },
      {
        "bool" : {
          "must" : [
            {
              "match" : {
                "title" : {
                  "query" : "продать",
                  "operator" : "OR",
                  "prefix_length" : 0,
                  "max_expansions" : 50,
                  "fuzzy_transpositions" : false,
                  "lenient" : false,
                  "zero_terms_query" : "NONE",
                  "boost" : 1.0
                }
              }
            },
            {
              "wildcard" : {
                "title" : {
                  "wildcard" : "купить*",
                  "boost" : 1.0
                }
              }
            }
          ],
          "should" : [
            {
              "bool" : {
                "must" : [
                  {
                    "match" : {
                      "description" : {
                        "query" : "продать",
                        "operator" : "OR",
                        "prefix_length" : 0,
                        "max_expansions" : 50,
                        "fuzzy_transpositions" : false,
                        "lenient" : false,
                        "zero_terms_query" : "NONE",
                        "boost" : 1.0
                      }
                    }
                  },
                  {
                    "wildcard" : {
                      "description" : {
                        "wildcard" : "купить*",
                        "boost" : 1.0
                      }
                    }
                  }
                ],
                "disable_coord" : false,
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "disable_coord" : false,
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
}

答案 1 :(得分:0)

如果我正确理解,这就是您所需要的

select * from Documents
join EVENTS on event_code = left (document_code, 6) 
WHERE 
EVENTS.Event_Status = 'Approved' AND Documents.document_code NOT LIKE '%APPROVED';
相关问题