Taffydb compare two columns

94 views Asked by At

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!

1

There are 1 answers

0
kaustubh shinde On BEST ANSWER

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.