mardi 1 décembre 2015

Sqlite3 – How can I get the timestamp from the result of SELECT max

My table is set up with columns for ID, Time, AAC, AAD, etc. The Time is the timestamp when the data was entered.

How am I able to get the value of the timestamp at the max value for each column?

import sqlite3

sqlite_file = 'foo.db'
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
column = ['AAC', 'AAD', 'ABC', 'ABP', 
          'AGL', 'AHG', 'AHY', 'AIO']
for i in range(len(column)):
    c.execute("SELECT max("'"%s"'") FROM prices" % (column[i]))
    print (column[i], c.fetchone())
conn.close()

Any help would be much appreciated!

Aucun commentaire:

Enregistrer un commentaire