So far in this chapter, we have looked at publishing layers based on traditional database tables; so now, we will look at GeoServer's ability to create SQL View layers. A SQL View layer is a kind of dynamic layer within GeoServer that allows for a custom SQL script to be executed on each request for data. A SQL View layer can be used to perform complex database queries to derive content for a layer, for example, selecting all the points of a certain type within a polygon and adding a count value to that polygon. The generated polygon layer can then be rendered with a color ramp to show the range of values.
You might be looking at this and thinking to yourself, "Why will I use a GeoServer SQL View over a database view?" There are a couple of reasons why GeoServer SQL Views might be preferable to database views:
You do not require access to the underlying database to create SQL View. However, you will require SQL-level access...