Function to create a view given a query.