简体   繁体   中英

Taffydb compare two columns

Let's say I have the following data

[{"variable":"ZENSARTECH","Date":"2017-10-11","value":740.05,"bbup":787.4447},
{"variable":"ZYDUSWELL","Date":"2017-10-11","value":885.7,"bbup":905.0995},
{"variable":"ECLERX","Date":"2017-10-11","value":1234.7,"bbup":1265.7899}]

const db = taffy(data);
const pdate = db().max("Date")
const fdb = db({Date: pdate})

Now what I want to do is get all the rows where value is greater than bbup column. So I want to compare two columns of the table rather than a column against a fixed value, the kind of examples shown in docs

fdata = fdb.filter({value:{gt:bbup}})

I tried the above but doesn't work. Is there a way to do this please? Seems like a very trivial SQL query.

Thanks!

This question was answered by the owner of taffydb github repo, typicaljoe. The discussion here.

https://github.com/typicaljoe/taffydb/issues/147#issuecomment-336234043

In summary, I was able to solve the above problem with

fdata = db(function () {
            return (this.value > this.sma20) ? true : false;
        })

His original discussion is highly recommended though. Very informative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM