查询数据表
现在您已经了解 datacamp_application 数据库的基本情况,接下来为该数据库编写一条查询语句。
本练习的目标是先熟悉数据。您将获取 3 位示例用户的评分数据,然后使用预定义的辅助函数 print_user_comparison(),比较这些用户所评分的课程 id 集合。
本练习是课程的一部分
Data Engineering 入门
练习说明
- 完成连接 URI。数据库名为
datacamp_application。主机为localhost,端口为5432。用户名为repl,密码为password。 - 选择用户 id 为
4387、18163和8770的评分记录。 - 将您选择的这 3 位用户填入
print_user_comparison()。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Complete the connection URI
connection_uri = "postgresql://____:____@____:____/datacamp_application"
db_engine = sqlalchemy.create_engine(connection_uri)
# Get user with id 4387
user1 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)
# Get user with id 18163
user2 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)
# Get user with id 8770
user3 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)
# Use the helper function to compare the 3 users
print_user_comparison(____, ____, ____)