Make a SQL query that varies on a table in Python

0

I want to write the result of several SQL queries that are dependent on a table res[ids] .

        for i, ids in enumerate(self.res['ids']):
            print ids
            cur.execute("""--- hashtag describiendo los grupos de subscriber_id 
            SELECT COUNT(swipe.eclipse_id), 
            subscriber_hashtag.hashtag_id
            FROM subscriber_hashtag
            INNER JOIN eclipse_hashtag ON eclipse_hashtag.hashtag_id = subscriber_hashtag.hashtag_id
            LEFT OUTER JOIN swipe ON subscriber_hashtag.subscriber_id = swipe.subscriber_id
            WHERE swipe.subscriber_id in %s 
            GROUP BY subscriber_hashtag.hashtag_id
                ORDER BY COUNT(swipe.eclipse_id) DESC;""",
            (tuple(self.res.iloc[i]['ids']),))
        n = cur.fetchall()
        print "n : "
        print n
        listado_description = [{"count": elem[0], "hashtag_id": elem[1],"eclipse_id": elem[2]} for elem in n]
        f= open("listado_description.js","w+")
        for item in listado_description:
            f.write("%s\n" % item)
        f.closed

At the moment it seems that only the last consulata is saved in listado_description because there is nothing in it but when I try to do it with things of res[ids] I get a result.

    
asked by ThePassenger 04.08.2017 в 17:03
source

0 answers