我正在尝试解决这个问题: 查找所有精灵的视频,其中创建者是唯一的观看者。基本上找到所有观看者是创作者的视频。
PreparedStatement pstmt = connection.prepareStatement("Select videoName from videos video natural join accountInformation natural join viewerAccount where " +
"viewerName = creatorName and video.videoName not in (Select videoName from videos natural join accountInformation natural join viewerAccount v where " +
"video.creatorName != v.viewerName);");
ResultSet resultSet = pstmt.executeQuery();
但是,我的查询从未产生结果。 有没有办法可以做到这一点?我觉得我有正确的主意,但我现在就被卡住了。请找到下表:
String viewerAccount = "create table viewerAccount ("
+ " viewerName CHAR(100),"
+ " accountID integer,"
+ " primary key(viewerName),"
+ " foreign key (accountID) references accounts)";
connection.createStatement().executeUpdate(viewerAccount);
String videos = "create table videos "
+ "(link CHAR(50),"
+ " creatorName VARCHAR(100),"
+ " videoName VARCHAR(100),"
+ " duration integer,"
+ " primary key(link))";
connection.createStatement().executeUpdate(videos);
String accountInfo = "create table accountInformation ("
+ " accountID integer,"
+ " time integer,"
+ " link CHAR(50),"
+ " primary key(accountID,time,link),"
+ " foreign key (accountID) references accounts,"
+ " foreign key (link) references videos)";
connection.createStatement().executeUpdate(accountInfo);