Processing data by python and SQL