AbstractThe recent years Wireless Sensor Networks (WSNs) have had a tremendous growth in interest, and advances in hardware and wireless network technologies have resulted in multifunctional and small low-cost and low-power sensor devices. These devices can be spread across a geographical area to collaborate among themselves to establish a sensor network. These devices have several distinguishing characteristics; they communicate with a low-range radio, they have very low processing power, and they have limited memory recourses. Given their limited power supply, they permit very low energy consumption. Further, they perform limited and specific monitoring and sensing functions.TinyDB is an experimental query processing middleware system, which runs on each of the nodes in a WSN. The primary goal of TinyDB is to make it easier to develop applications for WSNs. TinyDB frees the developer from the burden of writing low-level code for sensor devices like the sensor network interfaces. It offers a query language much like SQL for extracting information from the sensors. The current implementation of TinyDB has some weaknesses. First, queries containing aggregates produce incorrect values. Second, the HAVING clause in the query language is not implemented, and it is not possible to log aggregated queries to the PostgreSQL database. Finally, there is a considerable loss of messages in the network. It is vital that aggregation and grouping techniques are correctly implemented in a WSN, since those techniques reduce the amount of data that must be sent in the network, and thereby extending the life of battery powered WSNs. In addition, the HAVING clause is the only way to filter aggregated values. When the HAVING clause is implemented and applied in the network, it will reduce the amount of data sent in the network.In this thesis we develop a new implementation of TinyDB. It extends the query language with the HAVING clause, and the errors regarding aggregating functions and logging of aggregated data to the PostgreSQL database are corrected. We use the new implementation to investigate the reliability of TinyDB and perform an evaluation of the HAVING clause feature.