I'm trying to use a view with sqlalchemy_views.
view = Table('recap_results', MetaData())
definition = text("SELECT Team, SUM(win) as Win, SUM(draw) as Draw, SUM(loss) as Loss FROM \
(SELECT HomeTeam as Team, COUNT(*) AS nb_match, SUM(case when (FTR='H') then 1 else 0 end) AS win, \
SUM(case when (FTR='D') then 1 else 0 end) AS draw,\
SUM(case when (FTR='A') then 1 else 0 end) AS loss\
FROM data GROUP BY Team\
UNION ALL \
SELECT AwayTeam as Team, COUNT(*) AS nb_match, SUM(case when (FTR='A') then 1 else 0 end) AS win,\
SUM(case when (FTR='D') then 1 else 0 end) AS draw, \
SUM(case when (FTR='H') then 1 else 0 end) AS loss\
FROM data GROUP BY Team) \
GROUP BY Team ORDER BY Win DESC")
create_view = CreateView(view, definition)
And when I try to call this view it gives me an error:
test = "SELECT * FROM recap_results"
query(test).head()
OperationalError: (sqlite3.OperationalError) no such table: recap_results [SQL: "SELECT * FROM 'recap_results'"]
It does not recognize 'recap_results' view, how can I call it ?
Aucun commentaire:
Enregistrer un commentaire