added db functions for window functionality

this is a bit nitpicky but can you indent the boolean clauses in the `WHERE` statement?