python - MySQL 和 Python : How to map the table data?

标签 python mysql sql cursor

我有以下数据库结构:

TABLE 'images' (id,name,format)
TABLE 'objects'(id,title)
TABLE 'images_objects'(id,image_id,object_id)

其中image_idobject_id分别是images_objects表的外键。所以我填充了前两个表,现在我想用 id 对填充第三个表。我应该构建哪个 SQL 查询?

最佳答案

尝试计算两个表的笛卡尔积并填充映射表。

否定:

   insert 
     into images_objects
          (image_id
          ,object_id
          )
   select i.id as image_id
          ,o.id as object_id
     from images i
     join objects o 
       on 1=1

关于python - MySQL 和 Python : How to map the table data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53607344/

相关文章:

mysql - 如何计算 mysql 中计数列中值的总和?

sql - 如何使用单个Update查询更新列中的所有值?

mysql - 在MySQL中,如何进行日期查询?

python - Pandas 月滚动操作

python:基本 XML 解析错误(使用 lxml)

python - Pandas :将列值更改超过一定数量

php-返回2次之间的所有时间

php - SELECT DISTINCT 还是单独的规范化表?

mysql - SQL选择属于同一对象的用户

python - matplotlib.pyplot.draw() 和 matplotlib.pyplot.show() 没有效果