码迷,mamicode.com
首页 > 其他好文 > 详细

Working with Data Sources 9

时间:2016-11-22 09:51:25      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:query   clear   bsp   cer   with   cut   condition   join   source   

1. One to many relations:

  one value in column in table one related to several values in the column in table two. In this case, we need to be very clear that who is "one" and who is "many":

  cursor = conn.cursor()

  query =‘‘‘SELECT ceremonies.year,nominations.movie # select target column we want to fit into the query

   FROM nominations  # select table from the ‘one‘ table

   INNER JOIN ceremonies #select table from the ‘many‘ table

   ON ceremonies.id == nominations.ceremony_id # select revelent column

  WHERE nominations.nominee == "Natalie Portman"; # select conditions we would like to query
  ‘‘‘  

  cursor.execute(query)

  portman_movies = cursor.fetchall()

 

2.

Working with Data Sources 9

标签:query   clear   bsp   cer   with   cut   condition   join   source   

原文地址:http://www.cnblogs.com/kingoscar/p/6087826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!