我有两个数据库,我想将其中一个//For building aggregation query
def buildAgg(groups: Seq[String])(leafAggBuilder: () => AbstractAggregationDefinition): AbstractAggregationDefinition = {
groups match {
case x :: xs => aggregation.terms("termAgg").field(x).aggregations(buildAgg(xs)(leafAggBuilder))
case Nil => leafAggBuilder()
}
}
//An example leaf aggregation builder
def buildLeafAgg(aggFuncInfo: Pair[String, String])(): AbstractAggregationDefinition = {
aggFuncInfo._1 match {
case "avg" => aggregation.avg("aggFunc").field(aggFuncInfo._2)
case "sum" => aggregation.sum("aggFunc").field(aggFuncInfo._2)
case "cardinality" => aggregation.cardinality("aggFunc").field(aggFuncInfo._2)
case _ => aggregation.count("aggFunc").field(aggFuncInfo._2)
}
}
//For parsing aggregation
def parseAgg[T](groups: Seq[String], agg: Aggregation, allGroups: Seq[String])(leafAggParser: (Seq[String], Aggregation) => Seq[T]): Seq[T] = {
groups match {
case x :: xs => {
val groupAggs = agg.asInstanceOf[StringTerms].getBuckets.asScala.toList
(for {
groupAgg <- groupAggs
aa = groupAgg.getAggregations.asList.asScala.head
gkey = groupAgg.getKeyAsString
gacc = allGroups :+ gkey
} yield parseAgg(xs, aa, gacc)(leafAggParser)).flatten
}
case Nil => {
leafAggParser(allGroups, agg)
}
}
}
//An example leaf aggregation parser
def parseSimpleLeafAgg(allGroups: Seq[String], agg: Aggregation): Seq[GroupStats] = {
val value = agg.asInstanceOf[InternalNumericMetricsAggregation.SingleValue].value()
val groupId = allGroups.mkString(".")
Seq(GroupStats(groupId, value))
}
//Usage: Build Query and Parse result
def groupStats(groupFields: Seq[String]): Seq[GroupStats] = {
val resp = client.execute {
def leafPlainAggBuilder = buildLeafAgg(("count", "V1")) _
search(esIndex).size(0).aggregations(buildAgg(groupFields)(leafPlainAggBuilder))
}.await
//get the root aggregation
val agg = resp.aggregations.asList().asScala.head
def leafAggParser = parseSimpleLeafAgg _
val res = parseAgg(groupFields, agg, Seq())(leafAggParser)
res
}
列与另一个列中的varchar50AllowNulls
列进行比较。
我发现当我在varchar列中有一个值并且text列中有一个空字符串时,我对这些链接表的Access查询起作用。
但是当我在TextNotNull
中有一个空字符串并且在text列中有一个值时,它不起作用。
我找不到任何似乎可以解决这个问题的话题。我可以要求开发人员将文本更改为varchar
,但如果我可以使用SQL解析,我认为最好。
我的猜测是我需要施放或修剪,但我的努力没有成功。
varchar
答案 0 :(得分:2)
以下WHERE
子句的逻辑是,当可空VARCHAR
列的不等于非可空TEXT
时,您要删除记录柱。如果Varchar50AllowNulls
不 NULL
,则使用<>
的原始条件已经在检查此情况。但是,当Varchar50AllowNulls
NULL
时,<>
将不起作用,因为将NULL
的任何值进行比较是未知的。相反,由于TextNotAllowNulls
不能NULL
,因此无论Varchar50AllowNulls
是NULL
,您都希望删除此记录,而不管TEXT
列的值是什么。< / p>
SELECT A.EQNUM,
A.[Varchar50AllowNulls],
B.EQNUM,
B.[TextNotAllowNulls]
FROM A
INNER JOIN B
ON A.EQNUM = B.EQNUM
WHERE A.[Varchar50AllowNulls] <> B.[TextNotAllowNulls] OR
A.[Varchar50AllowNulls] IS NULL