inserting variable in mysql @ Python

sql=”’ %(utsav)s ”’ %dict(utsav:utsav)

example:

sql = “””
SELECT COALESCE(trp.relation, ‘TOTAL’) committed,
COUNT(DISTINCT trp.product_id) num_products
FROM %(wize_db)s.topic_related_product trp
JOIN topics t ON t.id = trp.topic_id
JOIN tmp_live_categories lc ON lc.id = t.category_id
WHERE t.is_live = ‘YES’
AND trp.relation != ‘DISABLED’
AND trp.score > 0
GROUP BY trp.relation
WITH ROLLUP
“”” % dict(wize_db=db.wize.bind.url.database)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: