return arg.reduce((prev, current) => prev + current)
我要列出动画列表
但是有问题
如果我尝试使用此代码,则每年只有四分之一的ID
例如,如果我将这4个动画添加到列表中
cur.execute('''
CREATE TABLE IF NOT EXISTS Title (
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT NOT NULL,
t_name TEXT UNIQUE,
genre_id INTEGER,
production_id INTEGER,
year_id INTEGER
)''')
cur.execute('''
CREATE TABLE IF NOT EXISTS Genre (
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT NOT NULL,
g_name TEXT UNIQUE
)''')
cur.execute('''
CREATE TABLE IF NOT EXISTS Production (
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT NOT NULL,
p_name TEXT UNIQUE
)''')
cur.execute('''
CREATE TABLE IF NOT EXISTS Year (
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT NOT NULL,
year TEXT UNIQUE,
quater_id INTEGER
)''')
cur.execute('''
CREATE TABLE IF NOT EXISTS Quater (
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT NOT NULL,
quater TEXT UNIQUE
)''')
while True:
i_title = input('Insert title: ')
i_genre = input('Insert genre: ')
i_production = input('Insert production: ')
i_year = input('Insert year: ')
i_quater = input('Insert quater: ')
try:
cur.execute('''INSERT OR IGNORE INTO Quater (quater) VALUES (?)''', (i_quater,))
f_quater = cur.execute("SELECT id From Quater WHERE quater = ?", [i_quater]).fetchone()[0]
cur.execute('''INSERT OR IGNORE INTO Year (year, quater_id) VALUES (?,?)''', (i_year, f_quater))
f_year = cur.execute("SELECT id From Year WHERE year = ?", [i_year]).fetchone()[0]
cur.execute('''INSERT OR IGNORE INTO Production (p_name) VALUES (?)''', (i_production,))
f_production = cur.execute("SELECT id From Production WHERE p_name = ?", [i_production]).fetchone()[0]
cur.execute('''INSERT OR IGNORE INTO Genre (g_name) VALUES (?)''', (i_genre,))
f_genre = cur.execute("SELECT id From Genre WHERE g_name = ?", [i_genre]).fetchone()[0]
cur.execute('''INSERT INTO Title (t_name, genre_id, production_id, year_id ) VALUES (?,?,?,?)''', (i_title, f_genre, f_production, f_year ))
conn.commit()
print('Data is inserted')
结果在“标题表”中是这样的
animation1, genre, production, 2018(year_id = 1), 4 quarter(quarter_id = 1)
animation2, genre, production, 2018(year_id = 1), 3 quarter(quarter_id = 2)
animation3, genre, production, 2018(year_id = 1), 2 quarter(quarter_id = 3)
animation4, genre, production, 2018(year_id = 1), 1 quarter(quarter_id = 4)
和“年表”
中---t_name-----genre_id--production_id-year_id------
animation1 genre_id production_id 1
animation2 1
animation3 1
animation4 1
和“季度表”中
id---year---quarter_id
1 2018 1
我想要这样的Year表中有4条记录
id---qurter---
1 4
2 3
3 2
4 1
所以当我连接所有表时,它显示如下
id---year---quarter_id
1 2018 1
2 2018 2
3 2018 3
4 2018 4
对不起,我不是英语母语人士,但希望您能理解我的意思