Current approaches to the query of wireless sensor networks address specific sources such as individual sensors or transducers. We believe that it is important to have a higher level mechanism of abstraction for querying a sensor network. In this work we aim at querying complex events, where such an event is modeled as a condition computed over a complex aggregate of sensed data. When the condition becomes true then the event is detected and tracked. In this paper we present a model for detecting and tracking such complex events in a WSN and we propose a declarative language for the event definition and for the detection and tracking specification and we also discuss its implementation guidelines.