added db functions for window functionality

Using execute to insert TABLE_NAME in the query creates errors. Maybe use format?

ex) for latest
query = ("SELECT * FROM {0} WHERE dump_time=(SELECT MAX("
            "dump_time) FROM {0});").format(TABLE_NAME)