added db functions for window functionality

can we format the SQL strings consistently?
I like the way you do it at the bottom of this file more personally