A virtual sensor network is designed to infer an approximation of real data when the physical sensor network cannot provide it, due to technical or economic reasons. In this paper, we propose an approach to model virtual sensor networks based on fuzzy logic. It relies on the hypothesis that the readings of the physical sensors are correlated. In particular, the virtual sensor network is able to learn the relationships between the physical quantities detected by the sensors and model them through fuzzy rules, which provide an approximation of the real values. In the proposed model, a set of fuzzy rules is derived for each physical sensor. It will provide an accurate approximation of the sensor readings when needed (e.g. sensor malfunction). The proposed approach has been designed as an extension of the well known Tree Routing protocol, used in sensor networks for transmitting sensed data to the base station. It has been implemented in Snlog, a language derived from Datalog that supports the development of distributed algorithms for Wireless Sensor Networks in a declarative way. The experimental evaluation reported in the paper shows the effectiveness and efficacy of our solutions.