관련없는 테이블의 데이터로 교차 테이블 채우기

앨런

웹에서 긁어 낸 json 데이터에서 관계형 데이터베이스 (다 대다)를 구축하고 있습니다. 두 개의 기본 데이터베이스가 있는데 하나에는 909 개의 행이 있고 다른 하나에는 13 개의 행이 있습니다. json 파일 내에서 링크되는 방법에 따라 큰 테이블의 ID를 교차 테이블의 작은 테이블의 ID와 일치시켜야합니다. 내가 찾은 문제는 이러한 테이블을 함께 관련시키는 것이 없지만 교차 테이블을 채워야한다는 것입니다. 수일이 걸리는 손으로하는 것 외에 내가 시도하거나 생각할 수있는 것은 아무것도 없습니다. 다음은 json 파일의 작은 샘플입니다. 큰 테이블에는 코스 정보가 있고 작은 테이블은 fulfills 키를 사용합니다.

[
{"number": "CHIN 242", "subject": "Chinese", "title": "Chinese Cinema and Chinese Modernity", "description": "From the fall of the Clestial Empire to the rise of China's economy today, Chinese cinema has witnessed many social changes in the modern era. This course will focus on the interaction between Chinese cinema and the process of modernization.", "fulfills": ["Human Expression\u2014Primary Texts", "Intercultural"]},

{"number": "CLAS 240", "subject": "Classics", "title": "Classical Mythology", "description": "A survey of the major myths and legends of ancient Greece and Rome.", "fulfills": ["Human Expression\u2014Primary Texts", "Quantitative"]},

{"number": "CLAS 250", "subject": "Classics", "title": "The World of Ancient Greece", "description": "A historical survey of ancient Greek culture from the Trojan War to the rise of Rome.", "fulfills": ["Human Expression\u2014Primary Texts", "Religion"]},

{"number": "CLAS 255", "subject": "Classics", "title": "Ancient Roman Culture", "description": "This course explores various cultural institutions and practices of the ancient Romans.", "fulfills": ["Human Expression\u2014Primary Texts", "Human Behavior"]},

{"number": "CLAS 265", "subject": "Classics", "title": "Greece and Rome on Film", "description": "This course explores the ways in which various events and episodes from Greek and Roman myth and history have been adapted for modern film and television.", "fulfills": ["Human Expression\u2014Primary Texts"]},

{"number": "CLAS 270", "subject": "Classics", "title": "Archaeology of Ancient Greece", "description": "An in-depth study of the archaeology of ancient Greece, with a focus on the high points of Greek civilization and material culture.", "fulfills": ["Historical", "Human Expression\u2014Primary Texts"]},

{"number": "CLAS 275", "subject": "Classics", "title": "Archaeology of Ancient Rome", "description": "This course explores the archaeology of ancient Rome from its early beginnings to its rapid growth into one of the world's largest empires.", "fulfills": ["Historical", "Human Expression\u2014Primary Texts"]},

{"number": "CLAS 300", "subject": "Classics", "title": "Classics and Culture", "description": "Using texts in translation, this course explores select aspects or themes from the cultures of ancient Greece and Rome.", "fulfills": ["Human Expression\u2014Primary Texts"]},
]
앨런

나는 이것에 대한 해결책을 찾았습니다. 교차 테이블을 채우려면 id에 대한 쿼리를 실행하고 작은 테이블과 id 및 숫자와 같은 간단한 것을 수행 한 다음 myDict = dict(map(reversed,cur.fetchall()))각 쿼리에 대해 실행 합니다. 거기에서 for 루프를 사용하여 json 데이터를 반복 한 다음 중첩 된 for 루프를 사용하여 fulfills 및 cur.execute(insert into ...). 다음과 같이 보입니다.

cur.execute('select id, fulfills from reqs;')
dict1 = dict(map(reversed,cur.fetchall()))
cur.execute('select id, number from course;')
dict2 = dict(map(reversed,cur.fetchall()))
for x in geneds:
    for y in x:
        cur.execute('insert into table(course, req) values(%s, %s);', (dict2[x['number']], dict1[y]))

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

직접 관련이없는 테이블의 Postgresql 교착 상태

분류에서Dev

데이터로 테이블 채우기

분류에서Dev

관련없는 테이블의 SQL보기

분류에서Dev

데이터베이스의 데이터로 데이터 테이블 채우기

분류에서Dev

모의 데이터로 접합 테이블 채우기

분류에서Dev

Bridge 테이블 채우기

분류에서Dev

다른 테이블의 값을 기반으로 테이블을 업데이트하는 MySQL 절차

분류에서Dev

json 데이터로 테이블을 채우는 방법

분류에서Dev

테이블이없는 경우 테이블 데이터를 다른 테이블로 이동

분류에서Dev

Eloquent로 관련 테이블 데이터 쿼리하기

분류에서Dev

복잡한 for 루프가있는 HTML의 테이블 채우기

분류에서Dev

JS 객체의 데이터로 데이터 테이블 채우기

분류에서Dev

겹치는 그룹으로 SQL 테이블의 누락 된 데이터 채우기

분류에서Dev

다차원 배열로 테이블을 채우는 방법

분류에서Dev

교수 테이블과 코스 테이블의 관계

분류에서Dev

cakephp의 메인 테이블과 직접 관련이없는 테이블 결합

분류에서Dev

날짜를 기반으로하는 동적 데이터로 도우미 테이블 채우기

분류에서Dev

AR 데이터 테이블의 행 채우기

분류에서Dev

테이블의 데이터를 사용하여 PHP 채우기

분류에서Dev

Laravel 5.4의 다른 테이블에 외래 키 제약 조건이있는 Users 테이블 채우기

분류에서Dev

MySQL에서 두 테이블의 교차 가져 오기

분류에서Dev

관련 테이블에 일치하는 항목이없는 경우 필드를 null 값으로 업데이트

분류에서Dev

두 SQL 테이블의 교차점에서 PHP로 데이터를 가져 오는 방법

분류에서Dev

json 데이터로 js 테이블 채우기

분류에서Dev

svelte에서 js 데이터로 html 테이블 채우기

분류에서Dev

CodeIgniter 테이블 데이터로 양식 입력 채우기

분류에서Dev

XML 데이터로 테이블 채우기 (Nokigiri / xpath 사용)

분류에서Dev

동적으로 Jquery 데이터 테이블 채우기

분류에서Dev

.csv를 데이터 테이블로 읽고 datagridview 채우기

Related 관련 기사

  1. 1

    직접 관련이없는 테이블의 Postgresql 교착 상태

  2. 2

    데이터로 테이블 채우기

  3. 3

    관련없는 테이블의 SQL보기

  4. 4

    데이터베이스의 데이터로 데이터 테이블 채우기

  5. 5

    모의 데이터로 접합 테이블 채우기

  6. 6

    Bridge 테이블 채우기

  7. 7

    다른 테이블의 값을 기반으로 테이블을 업데이트하는 MySQL 절차

  8. 8

    json 데이터로 테이블을 채우는 방법

  9. 9

    테이블이없는 경우 테이블 데이터를 다른 테이블로 이동

  10. 10

    Eloquent로 관련 테이블 데이터 쿼리하기

  11. 11

    복잡한 for 루프가있는 HTML의 테이블 채우기

  12. 12

    JS 객체의 데이터로 데이터 테이블 채우기

  13. 13

    겹치는 그룹으로 SQL 테이블의 누락 된 데이터 채우기

  14. 14

    다차원 배열로 테이블을 채우는 방법

  15. 15

    교수 테이블과 코스 테이블의 관계

  16. 16

    cakephp의 메인 테이블과 직접 관련이없는 테이블 결합

  17. 17

    날짜를 기반으로하는 동적 데이터로 도우미 테이블 채우기

  18. 18

    AR 데이터 테이블의 행 채우기

  19. 19

    테이블의 데이터를 사용하여 PHP 채우기

  20. 20

    Laravel 5.4의 다른 테이블에 외래 키 제약 조건이있는 Users 테이블 채우기

  21. 21

    MySQL에서 두 테이블의 교차 가져 오기

  22. 22

    관련 테이블에 일치하는 항목이없는 경우 필드를 null 값으로 업데이트

  23. 23

    두 SQL 테이블의 교차점에서 PHP로 데이터를 가져 오는 방법

  24. 24

    json 데이터로 js 테이블 채우기

  25. 25

    svelte에서 js 데이터로 html 테이블 채우기

  26. 26

    CodeIgniter 테이블 데이터로 양식 입력 채우기

  27. 27

    XML 데이터로 테이블 채우기 (Nokigiri / xpath 사용)

  28. 28

    동적으로 Jquery 데이터 테이블 채우기

  29. 29

    .csv를 데이터 테이블로 읽고 datagridview 채우기

뜨겁다태그

보관