I have a graph containing nodes related to weather conditions:
Annual Precipitation Amount (:YRC) with property rainfall,
Average Annual Temperature (:YTC) with property temp,
Air Quality (:AirQuality) with property ktons, :SoilMoisture at depth 10 cm, 20 cm, 50 cm, 100 cm with properties cm10, cm20, cm50, cm100.
And nodes that determine the harvest amount (:Prod) with the harvest property.
The share of each factor in the amount of harvest must be determined.
// The total sum of the influence of all meteorological factors is calculated
MATCH (f)-[:DETERMINE_PROD]->(:Prod)
WITH SUM(f.rainfall + f.temp + f.mm + f.ktons) AS totalInfluence
WHERE totalInfluence > 0
// Calculate the weights for each meteorological factor
MATCH (f)-[:DETERMINE_PROD]->(:Prod)
WITH
CASE
WHEN 'YRC' IN LABELS(f) THEN 'YRC'
WHEN 'YTC' IN LABELS(f) THEN 'YTC'
WHEN 'SoilMoisture' IN LABELS(f) THEN 'SoilMoisture'
WHEN 'AirQuality' IN LABELS(f) THEN 'AirQuality'
END AS factor,
SUM(f.rainfall + f.temp + f.cm10+f.cm20+f.cm50+f.cm100+ f.ktons) AS influence,
totalInfluence
RETURN factor, influence / totalInfluence AS weight
***RESULT:***
***(no changes, no records)***
Letโs break it down. Do both of these queries return results?
MATCH (f)-[:DETERMINE_PROD]->(:Prod)
WITH SUM(f.rainfall + f.temp + f.mm + f.ktons) AS totalInfluence
WHERE totalInfluence > 0
RETURN totalInfluence
WITH 1 as totalInfluence
MATCH (f)-[:DETERMINE_PROD]->(:Prod)
WITH
CASE
WHEN 'YRC' IN LABELS(f) THEN 'YRC'
WHEN 'YTC' IN LABELS(f) THEN 'YTC'
WHEN 'SoilMoisture' IN LABELS(f) THEN 'SoilMoisture'
WHEN 'AirQuality' IN LABELS(f) THEN 'AirQuality'
END AS factor,
SUM(f.rainfall + f.temp + f.cm10+f.cm20+f.cm50+f.cm100+ f.ktons) AS influence,
totalInfluence
RETURN factor, influence / totalInfluence AS weight
Do all you โfโ nodes always contain only one label, or could the have multiple labels? We can eliminate the case statement if each always has just one label.
Based on those results, the sum calculated in the first query with be zero. As such, the โwhereโ clause of the first query must be stopping the query, giving you no result.