下面是我需要帮助的数据库的一部分。
DROP DATABASE IF EXISTS bookex;
CREATE DATABASE bookex;
use Bookex;
CREATE TABLE Reviewer(
ReviewerID INT,
Name VARCHAR(20) NOT NULL,
EmployedBy CHAR(30),
constraint reviewer_reviewerID_pk PRIMARY KEY (reviewerID)
);
CREATE TABLE Book(
ISBN CHAR(13),
Title VARCHAR(70) NOT NULL,
Description VARCHAR(100),
Category INT,
Edition CHAR(30),
PublisherID INT NOT NULL,
constraint book_ISBN_pk PRIMARY KEY (ISBN)
);
CREATE TABLE BookReview(
ISBN CHAR(13) NOT NULL,
ReviewerID INT NOT NULL,
Rating INT,
Comments VARCHAR(255),
constraint bookreview_pk PRIMARY KEY (ISBN, ReviewerID),
constraint bookreview_ISBN_fk FOREIGN KEY (ISBN) REFERENCES Book(ISBN),
constraint bookreview_reviewerID_fk FOREIGN KEY (ReviewerID) REFERENCES Reviewer(ReviewerID)
);
--
-- Dumping data for table 'reviewer'
--
INSERT INTO reviewer VALUES (1,'Jacobs','Gadget Boy');
INSERT INTO reviewer VALUES (2,'Troell','Dallas Underground');
INSERT INTO reviewer VALUES (3,'Bills','The RIT Reporter');
INSERT INTO reviewer VALUES (4,'Hill','Microsoft News');
INSERT INTO reviewer VALUES (5,'Kurtz','MacIntosh News');
INSERT INTO reviewer VALUES (6,'Leone',null);
INSERT INTO reviewer VALUES (7,'Doubleday','Media Mania');
INSERT INTO reviewer VALUES (8,'Wells','The RIT Reporter');
INSERT INTO reviewer VALUES (9,'Worthington','The Annex');
INSERT INTO reviewer VALUES (10,'Lawson','The Last Word');
INSERT INTO reviewer VALUES (11,'Lasky',null);
INSERT INTO reviewer VALUES (12,'Rozanski',null);
INSERT INTO reviewer VALUES (13,'Whittington','JAVA Rocks');
INSERT INTO reviewer VALUES (14,'Holden',null);
INSERT INTO reviewer VALUES (15,'Stratton','Harvard Lampoon');
INSERT INTO reviewer VALUES (16,'Johnson','NRA Weekly');
INSERT INTO reviewer VALUES (17,'Mason','BMW Owners Quarterly');
INSERT INTO reviewer VALUES (18,'Goodman','MacIntosh News');
INSERT INTO reviewer VALUES (19,'Phelps','Detroit News');
INSERT INTO reviewer VALUES (20,'Yacci','The Learning Channel');
INSERT INTO reviewer VALUES (24,'Weeden','Scrye');
INSERT INTO reviewer VALUES (25,'McVea','Programming Central');
INSERT INTO reviewer VALUES (26,'Perez-Hardy','The Network Voice');
INSERT INTO reviewer VALUES (27,'Heartthrob','Journal of Romance');
INSERT INTO reviewer VALUES (28,'Bierre','JAVA Rocks');
INSERT INTO reviewer VALUES (29,'Axelrod','JAVA Rocks');
-- Dumping data for table 'book'
--
INSERT INTO book VALUES ('1-111-11111-4','Women are From Venus ORACLE is from Beyond Pluto','New York Times Best Seller 27 weeks',1,'4',1);
INSERT INTO book VALUES ('1-222-32443-7','Calculus for Phys Ed Majors','Carry our 200 lb text book: learn integrals and keep in Shape',7,'3',7);
INSERT INTO book VALUES ('1-295-84547-1','My Love\'s Last Longing','Volume 1 of 4',1,'1',4);
INSERT INTO book VALUES ('1-533-73363-8','From the Shores of Lake Erie to IT','One man\'s Journey to IT',8,'2',1);
INSERT INTO book VALUES ('1-559-68777-1','My Love\'s Last Lingering Lost','Volume 2 of 4',1,'1',4);
INSERT INTO book VALUES ('1-932-87447-6','The Science of Literature Searching','A Book Worth a Look is Worth a Good Look Up',6,'1',5);
INSERT INTO book VALUES ('2-089-77869-5','Yes! Networking is for Bills Fans','How to Use a Spanning Tree to Exit Rich Stadium',9,'1',8);
INSERT INTO book VALUES ('2-122-29058-5','How to Keep your Cellular Bill Down','How to carry 500 Miles of Fiber in Your Wallet',5,'2',2);
INSERT INTO book VALUES ('2-221-11341-5','Tired of wired? Infrared instead!','500 Ways to pull out your hair while pulling out all your cable',5,'1',2);
INSERT INTO book VALUES ('3-444-95595-4','ER, SOM, NF, DK/NF, SQL, JDBC, ODBC, and RELVAR','How U can avoid being trapped in Database acronyms',4,'1',3);
INSERT INTO book VALUES ('3-445-43341-2','Master Wireless Through The Classic Comics','Infrared man triumphs over Cable Guy and CoAx NastyMan',2,'1',6);
INSERT INTO book VALUES ('3-445-58668-5','How to Keep your Cable Bill Down','How to Avoid Tripping on 500 Miles of Fiber in your wallet',5,'1',10);
INSERT INTO book VALUES ('4-344-22221-1','I Lasted my Love\'s Last Lingering Longing','Volume 3 of 4',1,'2',4);
INSERT INTO book VALUES ('4-668-39283-8','From Deep in the Heart of Texas to IT','One man\'s Journey to IT',8,'1',1);
INSERT INTO book VALUES ('5-538-55746-1','My Lost Love\'s Long Last Lingering','Volume 4 of 4',1,'1',4);
INSERT INTO book VALUES ('6-449-68668-8','From Brockport to IT','Prof. Johnson\'s Journey to IT (about 25 min via 490)',8,'1',1);
INSERT INTO book VALUES ('7-999-14432-2','Master HTML Through The Classic Comics','Using his Super Web thrower, Spiderman creates HTML docs',2,'2',6);
INSERT INTO book VALUES ('8-330-69586-6','The Shortest Book in the World','A Guide to how Detroit will win the World Series in 2001',9,'1',3);
INSERT INTO book VALUES ('9-333-44441-1','My Love\'s at Long Last Lost his Lingering','Volume 5 of 4',1,'1',4);
INSERT INTO book VALUES ('9-337-55467-3','How to add Class to your Programming','How to write programs in VB instead of C',3,'3',10);
INSERT INTO book VALUES ('9-400-55555-2','Master C++ Through The Classic Comics','GeekMan triumphs over C++ program infected with Kryptonite virus',2,'1',6);
INSERT INTO book VALUES ('9-444-43356-3','A language without Pointers? Priceless.','For Everything Else, there\'s C++',3,'1',13);
INSERT INTO book VALUES ('9-455-61223-3','JAVA: It\'s more than Just a Programming Language','Achieve enlightenment through the mystery of the Swing package',3,'1',7);
INSERT INTO bookreview VALUES ('1-111-11111-4',19,10,'Hold on to your hats, gang! If you think a cookbook or the yellow pages is exciting reading, you gotta read Professor Spadas remarkable treatise on enriching you personal relationships through your knowledge of ORACLE 8.1.6. In an easy-to-read fashion, s');
INSERT INTO bookreview VALUES ('1-295-84547-1',27,10,'This is one of the most outstanding books ever written. Five thumbs up. Five stars. A must-read for everyone.');
INSERT INTO bookreview VALUES ('1-533-73363-8',20,4,'A rather boring autobiography of a northern Ohio native who migrates to Rochester New York where he becomes a professor of Information Technology at RIT. Other than the chapters devoted to the Cleveland Indians (chapters 1, 2, 3, 6, 10, 11, 12, 13), The C');
INSERT INTO bookreview VALUES ('1-559-68777-1',2,8,'A wonderful romance novel about Matt, a successful editor for the New York Times, who resigns and retreats to a Dude Ranch in New Mexico to find himself. Matt meets Margaret, a person with cowgirl charm in touch with her masculine self. Matt falls in lov');
INSERT INTO bookreview VALUES ('1-559-68777-1',19,9,'A wonderful romance novel about Margaret, a successful editor for the New York Times, who resigns and retreats to a Dude Ranch in New Mexico to find herself. Margaret meets Matt, a person with tough cowboy swagger in touch with his feminine self. Margare');
INSERT INTO bookreview VALUES ('2-089-77869-5',5,5,'Definitely dont buy this book if you are a Giants fan. Two Giants fans tried this technique at the Giants game several weeks ago and they arent back yet.');
INSERT INTO bookreview VALUES ('2-089-77869-5',13,8,'For any networking buff/Bills fan, Dr. Lutz treatise on the use of spanning trees to exit a Buffalo Bills game is a must. It is difficult to slog through in spots, but he shows you that by applying his minimalization technique you can get back to Rochest');
INSERT INTO bookreview VALUES ('2-089-77869-5',15,6,'Dont buy this book unless your are Bills fan. Fans of any other team will find their departure time from a Bills game actually triples when the technique is applied. In fact, it probably accounts for why Dr. Lutz (and any other Bills fan who applies it');
INSERT INTO bookreview VALUES ('2-122-29058-5',6,7,'Professor Hartpence shows you how to carry 500 miles of fiber in your wallet. Warning to the unwary: dont buy this book unless you have deep pockets.');
INSERT INTO bookreview VALUES ('2-122-29058-5',13,8,'Watch out Jim Carey .. this non-cable guy may leave you out of work. In his book, Professor Hartpence combines his cellular and networking skills with his experience in both the military and the commercial world and the practice of Zen to show you how to');
INSERT INTO bookreview VALUES ('3-444-95595-4',3,4,'U lose if you ever bother to read this book.');
INSERT INTO bookreview VALUES ('3-445-58668-5',6,7,'This book is a follow-up to Professor Hartpences book on how to carry 500 miles of fiber in your wallet.');
INSERT INTO bookreview VALUES ('4-344-22221-1',24,7,'A wonderful romance novel about Nelson, a successful editor for the New York Times, who resigns and retreats to a Dude Ranch in New Mexico to find himself. Nelson meets Laura, a person with cowgirl charm in touch with her masculine self. Nelson falls in');
INSERT INTO bookreview VALUES ('4-668-39283-8',6,6,'A sometimes boring autobiography of a Texan transplanted to Rochester New York where he becomes a professor of Information Technology at RIT. Other than the chapters devoted to the Dallas Cowboys (chapters 1, 2, 3, 6, 10, 11, 12, 13), The Presidential ele');
INSERT INTO bookreview VALUES ('5-538-55746-1',15,9,'A wonderful romance novel about Laura, a successful editor for the New York Times, who resigns and retreats to a Dude Ranch in New Mexico to find herself. Laura meets Nelson, a person with tough cowboy swagger in touch with his feminine self. Laura falls');
INSERT INTO bookreview VALUES ('6-449-68668-8',20,7,'The funny, often racy, autobiography of Daryl Johnson and his escapades to and from RIT. The book is largely about the excitement of commuting from the west side to RIT every day and how much fun it can be. A great book for those who live on the west side');
INSERT INTO bookreview VALUES ('6-449-68668-8',26,10,'An absolutely outstanding autobiography of a Saint John Fisher Graduate and how he has adapted to his 20 minute ride (mostly on 490) to RIT every morning and his 20 ride (mostly on 490) home from RIT every night. The author uses thirteen chapters to vibra');
INSERT INTO bookreview VALUES ('8-330-69586-6',5,10,'Geez .. no pages, no paragraphs, no words .. not even an illustration. But he did dedicate the book to Tony Clark. Says something for the fervor of this Detroit Tigers fan.');
INSERT INTO bookreview VALUES ('8-330-69586-6',15,10,'Very accurate analysis of a problem that is not NP complete.');
INSERT INTO bookreview VALUES ('9-333-44441-1',24,7,'Throwing the usual themes and twists of a romance novel to the winds, the author tells the store of Laura, a successful Dude Ranch owner in New Mexico, who resigns and moves to New York to seek her fortune as an editor for the New York Times. Laura meets');
INSERT INTO bookreview VALUES ('9-337-55467-3',25,9,'These authors know their way around a coding pad, let me tell you! In clear, bell-shaped tones, with succinct wording and pinpoint accuracy, they nail this subject matter to the wall. Do you like inheritance? How about information hiding? Maybe you like e');
INSERT INTO bookreview VALUES ('9-455-61223-3',13,9,'Professor Sonstein shows how oneness with the spiritual universe can be achieved by bringing the soul into rhytmn with the JAVA runtime machine. He shows that through various forms of self denial, such as writing code without pointers and heavy weight com');
我需要帮助显示评论者的姓名、书名和评论者给这本书的评分。 但仅限于 EmployedBy 字段为空的审阅者。
它应该是这样的:
name | title | rating
Leone | How to Keep your Cellular Bill Down | 7
Leone | How to Keep your Cable Bill Down | 7
Leone | From Deep in the Heart of Texas to IT | 6
我需要使用内部联接、联合还是仅使用多重 SELECT?
最佳答案
在旧版本 (4.24) 的 MySql 上测试了您的数据,这应该是您的查询
SELECT r.Name, b.Title, br.Rating
FROM Reviewer r JOIN BookReview br on br.ReviewerID = r.ReviewerID
JOIN Book b ON b.ISBN = br.ISBN
WHERE r.EmployedBy IS NULL OR r.EmployedBy = ''
这是结果
“Leone”,“如何降低手机账单”,7
“Leone”,“如何降低有线电视费用”,7
“Leone”,“从德克萨斯州的中心深处到 IT”,6
关于mysql - 连接多个表中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13184949/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以