Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNeana Del Rio
4,770 PointsChallenge Task 1 of 1 The movie theater wants to know how many movies they have in their database
Not sure where to start
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine(βsqlite:///movies.dbβ, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Movie(Base):
__tablename__ = βmoviesβ
id = Column(Integer, primary_key=True)
movie_title = Column(String)
genre = Column(String)
# Write your code below
2 Answers
kevin stradtman
10,172 PointsI finally figured this out the_movies = session.query(Movie.movie_title).filter(Movie.movie_title.like("%The%")).count()
Steven Parker
231,268 PointsStart by making the variable and beginning the assignment. You know the value will involve calling the .query
method on the session
, and using .filter
on the movie_title
attribute of the Movie
, making use of .like
as mentioned in the hints.
You might want to review the Analyze Books video, particularly about half way through where a very similar query to find specific book titles is constructed.
Neana Del Rio
4,770 PointsNeana Del Rio
4,770 PointsChallenge Task 1 of 1 The movie theater wants to know how many movies they have in their database with βTheβ in the title. They want to post this fun fact on their social media. Create a new variable called the_movies that holds a query to find all products with β%The%β in the movie_title and counts the number of returned values.\n*Hint:* Use filter() with .like()