bhavul
4/23/2019 - 7:25 PM

sql in jupyter

# install
pip install sql_magic


# then : 
import pandas as pd
pd.read_sql("SELECT c.id, c.name, COUNT(cg.genre_id) as num_of_genres FROM content c JOIN content_genre cg ON c.id = cg.content_id WHERE c.id NOT IN (SELECT cg.content_id FROM content_genre cg JOIN content_platform cp ON cg.content_id = cp.content_id WHERE cg.genre_id = 619555) and c.id IN (select cp.content_id from content_platform cp) GROUP BY c.id order by num_of_genres desc;", db.db.session.bind)