为什么我的代码只显示一本JK罗琳的书?它应该起作用吗



我想让它展示JK罗琳哈利波特系列的所有书籍,但出于某种原因,它只展示了第一本。我该如何解决这个问题?select语句中似乎有一个错误,但我似乎找不到它是什么。有人能帮忙吗?我只想在引文中键入随机单词,因为stackoverflow说我的帖子主要是代码,我需要添加更多细节。

create table authors (id integer primary key autoincrement, fullname TEXT, language TEXT, birthdate integer, deathdate integer, books integer, notes text);
insert into authors (fullname, language, birthdate, deathdate, books) values ("William Shakespeare",  "English", 1564, 1616, 39);
insert into authors (fullname, language, birthdate, books) values ("J. K. Rowling",  "English", 1965, 15);

insert into authors (fullname, language, birthdate, books, notes) values ("Gordon Korman",  "English", 1963, 82, "Only favorite books");


create table books (author_id integer, name text, publish_year integer);
insert into books VALUES (1, "The Two Gentlemen of Verona", 1589);  
insert into books VALUES (1, "The Comedy of Errors", 1589); 
insert into books VALUES (1, "Titus Andronicus", 1591); 
insert into books VALUES (1, "The Taming of The Shrew", 1593);
insert into books VALUES (1, "Love Labours Lost", 1589);
insert into books VALUES (1, "Romeo and Juliet", 1594);
insert into books VALUES (1, "A Midsummer's Night's Dream", 1595);
insert into books VALUES (1, "King John", 1595);
insert into books VALUES (1, "The Merchant of Venice", 1596);
insert into books VALUES (1, "The Merry Wives of Windsor", 1597);
insert into books VALUES (1, "Much Ado About Nothing", 1598);
insert into books VALUES (1, "As You Like It", 1599);
insert into books VALUES (1, "Julius Caesar", 1599);
insert into books VALUES (1, "Troilus and Cressida", 1600);
insert into books VALUES (1, "Hamlet", 1600);
insert into books VALUES (1, "Twelfth Night or What You Will", 1601);
insert into books VALUES (1, "All's Well That Ends Well", 1603);
insert into books VALUES (1, "Measure for Meausre", 1603);
insert into books VALUES (1, "Othello", 1603);
insert into books VALUES (1, "Timon of Athens", 1604);
insert into books VALUES (1, "King Lear", 1605);
insert into books VALUES (1, "Macbeth", 1606);
insert into books VALUES (1, "Pericles", 1607);
insert into books VALUES (1, "Antony and Cleopatra", 1608);
insert into books VALUES (1, "Coriolanus", 1608);
insert into books VALUES (1, "Cymbeline", 1609);
insert into books VALUES (1, "The Winter's Tale", 1609);
insert into books VALUES (1, "The Tempest", 1610);
insert into books VALUES (1, "The Two Noble Kinsmen", 1611);
insert into books VALUES (1, "Cardenio", 1612);
insert into books VALUES (1, "Henry VIII", 1613);
insert into books VALUES (1, "Henry V", 1599);
insert into books VALUES (1, "Richard III", 1593);
insert into books VALUES (1, "Richard II", 1595);
insert into books VALUES (2, "Fantastic Beasts and Where to Find Them", 2001);
insert into books VALUES (2, "Quidditch Through the Ages", 2001);
insert into books VALUES (2, "The Tales of Beedle the Bard", 2008);
insert into books VALUES (2, "Hogwarts: An Incomplete & Unreliable Guide", 2016);
insert into books VALUES (2, "Short Stories from Hogwarts of Heroism, Hardship and Dangerous Hobbies", 2016);
insert into books VALUES (2, "Short Stories from Hogwarts of Power, Politics and Pesky Poltergeists", 2016);
insert into books VALUES (3, "Losing Joe's Place", 1990);
insert into books VALUES (3, "The Sixth Grade Nickname Game", 1998);
insert into books VALUES (3, "Schooled", 2007);
insert into books VALUES (3, "The Juvie Three", 2008);
insert into books VALUES (3, "Ungifted", 2012);
insert into books VALUES (3, "Restart", 2018);
insert into books VALUES (3, "Whatshisface", 2018);
insert into books VALUES (3, "The Unteachbles", 2019);
insert into books VALUES (3, "Notorius", 2020);
select authors.fullname as Author, books.name as "Name", books.publish_year as "Year Published" from books left outer join authors on books.author_id = authors.id;
create table series (id integer primary key autoincrement, series_id text, name_book text);
insert into series (series_id, name_book) VALUES("1-1", "Henry VI, Part One");
insert into series (series_id, name_book) VALUES("1-1", "Henry VI, Part Two");
insert into series (series_id, name_book) VALUES("1-1", "Henry VI, Part Three");
insert into series (series_id, name_book) VALUES("1-2", "Henry IV, Part One");
insert into series (series_id, name_book) VALUES("1-2", "Henry IV, Part Two");
insert into series (series_id, name_book) VALUES("2-1", "Harry Potter and the Philosopher's Stone");
insert into series (series_id, name_book) VALUES("2-2", "Harry Potter and the Chamber of Secrets");
insert into series (series_id, name_book) VALUES("2-3", "Harry Potter and the Priosner of Azkaban");
insert into series (series_id, name_book) VALUES("2-4", "Harry Potter and the Goblet of Fire");
insert into series (series_id, name_book) VALUES("2-5", "Harry Potter and the Order of the Phoenix");
insert into series (series_id, name_book) VALUES("2-6", "Harry Potter and the Half-Blood Prince");
insert into series (series_id, name_book) VALUES("2-7", "Harry Potter and the Deathly Hallows");
insert into series (series_id, name_book) VALUES("2-8", "Harry Potter and the Cursed Child, Parts I & II");
insert into series (series_id, name_book) VALUES("3-1", "Slacker");
insert into series (series_id, name_book) VALUES("3-1", "Level 13");
insert into series (series_id, name_book) VALUES("3-2", "Masterminds");
insert into series (series_id, name_book) VALUES("3-2", "Criminal Destiny");
insert into series (series_id, name_book) VALUES("3-2", "Payback");
insert into series (series_id, name_book) VALUES("3-3", "The Hypnotists");
insert into series (series_id, name_book) VALUES("3-3", "Memory Maze");
insert into series (series_id, name_book) VALUES("3-3", "The Dragonfly Effect");
insert into series (series_id, name_book) VALUES("3-4", "Ungifted");
insert into series (series_id, name_book) VALUES("3-4", "Supergifted");
create table series_id (author_id integer, series_id text, series_name text, books_in_series integer, start_year integer);
insert into series_id VALUES (1, "1-1", "Henry VI", 3, 1590);
insert into series_id VALUES (1, "1-2", "Henry IV", 2, 1596);
insert into series_id VALUES (2, "2-1",  "Harry Potter", 8, 1997);
insert into series_id VALUES (3, "3-1",  "Slacker", 2, 2016);
insert into series_id VALUES (3, "3-2",  "Masterminds", 3, 2015);
insert into series_id VALUES (3, "3-3", "The Hypnotists", 3, 2013);
insert into series_id VALUES (3, "3-4",  "Ungifted", 2, 2012);
select authors.fullname, series_id.series_name, series_id.books_in_series, series_id.start_year, series.id, series.name_book from series_id join authors on series_id.author_id = authors.id join series on series_id.series_id = series.series_id order by series.id;

author_id = 2只有一个联接,并且它在series_id = "2-1":上

insert into series_id VALUES (2, "2-1",  "Harry Potter", 8, 1997);
insert into series (series_id, name_book) VALUES("2-1", "Harry Potter and the Philosopher's Stone");

看起来您正在将多个东西塞进series_id中,即一个实际的series_id和该系列中的一个序列。我建议您为每个概念创建单独的列。

请参阅第一个普通形式-列应仅包含1个值。

最新更新