0

我想在 cb 中创建一个视图,它将根据日期范围输入显示一些数据。

我的问题是如何从数据中区分字段?这是我的地图代码:

function (doc, meta) {
  if(!doc.clipGeneration.fromCache){
    var eiid = doc.clipGeneration.batchId;
    if (eiid == null){
        eiid = "API";
    }
    if (  !(doc.clipGeneration.externalId.indexOf("API_INTERVAL_TEST")>=0) )   {
    emit([doc.clipGeneration.clipStyle, eiid,doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
        emit([doc.clipGeneration.clipStyle, "ALL",doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
    emit([doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.clipGeneration.clipStyle], doc.insertRawTimestamp);
    }
  }
}

reduce 是 _count,过滤器例如是:

开始键:[2015,1,1,null]

结束键:[2015,1,31,"\uffff"]

输出符合日期范围的预期:

{"key":[2015,1,11,"5001188"],"value":1},
{"key":[2015,1,12,"100022"],"value":5},
{"key":[2015,1,12,"155"],"value":11},
{"key":[2015,1,13,"100022"],"value":9},
{"key":[2015,1,13,"155"],"value":6},
{"key":[2015,1,13,"5001159"],"value":1},
{"key":[2015,1,13,"5001190"],"value":3},
{"key":[2015,1,14,"100022"],"value":12},
{"key":[2015,1,14,"5001194"],"value":1},
{"key":[2015,1,15,"100022"],"value":11},
{"key":[2015,1,16,"100022"],"value":10},
{"key":[2015,1,18,"100022"],"value":8},
{"key":[2015,1,18,"5001096"],"value":6},
{"key":[2015,1,18,"5001194"],"value":3}

但是你可以看到“100022”重复了很多次,我怎样才能在 sql 中使类似的东西变得不同,所以它只会显示一次?

谢谢

4

1 回答 1

0

没有办法真正使只有 ID 字段不同。您可以按键减少,但只能减少整个密钥 - 所以 [date, id] 在您的情况下。您可以在 N1QL 中执行此操作,因为它与 SQL 一样具有实际的 DISTINCT 关键字,但目前仍处于开发人员预览中。

于 2015-04-21T14:09:35.830 回答