Everytime I try to divide something in neo4j, I keep getting zero. I am using the following query:
MATCH (m:Member)-[:ACTIVITY{issue_d:"16-Jan"}]->(l:Loan)
MATCH (m)-[:ACTIVITY]->(p:Payments)
WHERE l.installment<1000 AND p.total_pymnt>0
RETURN (l.funded_amnt-p.total_pymnt),(l.funded_amnt-p.total_pymnt)/(l.funded_amnt), l.funded_amnt, p.total_pymnt, m.member_id
LIMIT 1000;
I checked to make sure that my values for funded_amnt
and total_pymnt
are not messing up the operation they seem good:
Even when I just do:
500/l.funded_amnt
I still get zero. What am I doing wrong?
With UNWIND , you can transform any list back into individual rows. These lists can be parameters that were passed in, previously collect -ed result or other list expressions. One common usage of unwind is to create distinct lists. Another is to create data from parameter lists that are provided to the query.
To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.
The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.
The size of the available heap memory is an important aspect for the performance of Neo4j. Generally speaking, it is beneficial to configure a large enough heap space to sustain concurrent operations. For many setups, a heap size between 8G and 16G is large enough to run Neo4j reliably.
Multiply your numerator by 1.0.
MATCH (m:Member)-[:ACTIVITY {issue_d:"16-Jan"}]->(l:Loan)
MATCH (m)-[:ACTIVITY]->(p:Payments)
WHERE l.installment < 1000 AND p.total_pymnt > 0
RETURN (l.funded_amnt - p.total_pymnt), ((l.funded_amnt - p.total_pymnt) * 1.0) / l.funded_amnt, l.funded_amnt, p.total_pymnt, m.member_id
LIMIT 1000;
Integer division discards the remainder, so you need to multiply your numerator by 1.0 or wrap it in toFloat()
.
RETURN 5 / 12; // 0
RETURN 5 * 1.0 / 12; // 0.4166666666666667
RETURN toFloat(5) / 12; // 0.4166666666666667
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With