I have a file temperature.txt
with columns:
city
avghigh
avglow
coldmonth
coldavghigh
coldavglow
warmmonth
warmavghigh
warmavglow
I need to return the names of the cities which have the same average low temperature. I also have this function:
def run_query(db, q, args=None):
conn = sqlite3.connect(db)
cur = conn.cursor()
if args is None:
cur.execute(q)
else:
cur.execute(q, args)
results = cur.fetchall()
cur.close()
conn.commit()
conn.close()
return results
all I got thus far (If it's correct is)
return run_query(noname.db, ('Select Cities, AvgLow from Table')
In SQL, this can be easily done using a self join on the table to get matching AvgLow for different cities like this:
Select
t.Cities,
t.AvgLow
from Table1 t
INNER JOIN Table1 t1 ON t.AvgLow = t1.AvgLow
and t.Cities <> t1.Cities
ORDER BY t.AvgLow;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.