import pyodbc conn = "DRIVER={IME_DRIVERJA};SERVER=tup.fri.uni-lj.si;DATABASE=travian;UID=mstup;PWD=msfri;PORT=1433" conn = "DSN=MSTUP;UID=mstup;PWD=msfri" cnxn = pyodbc.connect(conn) cursor = cnxn.cursor() cursor.execute("DROP TABLE IF EXISTS Top10") cursor.execute("CREATE TABLE Top10 AS " "SELECT p.pid, p.player, SUM(v.population) AS population " "FROM igralec p, vas v " "WHERE p.pid = v.pid" "GROUP BY p.pid, p.player" "ORDER BY population DESC " "LIMIT 10;") cursor.commit() data = cursor.execute("SELECT * FROM Top10").fetchall() for item in data: stolpec(item.population, item.pid)