在下面这两个表中查询郭玉姣”借阅的图书名称CREATE TABLE `record` ( `recordid` INT(11) NOT NULL COMMENT '记录号', `readerid` CHAR(13) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '读者号', `bookid` CHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '图书号', `outdate` DATE NOT NULL COMMENT '借出日期', `indate` DATE DEFAULT NULL COMMENT '还入日期', `state` VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '当前状态', PRIMARY KEY (`recordid`), KEY `readerid` (`readerid`), KEY `bookid` (`bookid`), CONSTRAINT `record_ibfk_1` FOREIGN KEY (`readerid`) REFERENCES `reader` (`readerid`), CONSTRAINT `record_ibfk_2` FOREIGN KEY (`bookid`) REFERENCES `book` (`bookid`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;CREATE TABLE `reader` ( `readerid` CHAR(13) NOT NULL COMMENT '读者编号', `readername` VARCHAR(20) NOT NULL COMMENT '姓名', `typeid` TINYINT(4) DEFAULT NULL COMMENT '类别编号', `birthday` DATE DEFAULT NULL COMMENT '生日', `sex` CHAR(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '男' COMMENT '性别', `tel` CHAR(11) DEFAULT NULL COMMENT '电话', `enrolldate` DATE NOT NULL COMMENT '注册日期', `state` CHAR(10) DEFAULT NULL COMMENT '状态', PRIMARY KEY (`readerid`), KEY `typeid` (`typeid`), CONSTRAINT `reader_ibfk_1` FOREIGN KEY (`typeid`) REFERENCES `readertype` (`typeid`), CONSTRAINT `reader_chk_1` CHECK (((`sex` = _utf8mb4'男') OR (`sex` = _utf8mb4'女'))), CONSTRAINT `reader_chk_2` CHECK (((`state` = _utf8mb3'有效') OR (`state` = _utf8mb3'无效'))) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
时间: 2023-07-13 16:28:53 浏览: 157
学堂云 雨课堂 2020秋-工程伦理 杨玉姣老师 期末考试题及答案(原题).pdf
可以使用以下 SQL 语句查询:
SELECT book.bookname
FROM record
JOIN reader ON record.readerid = reader.readerid
JOIN book ON record.bookid = book.bookid
WHERE reader.readername = '郭玉姣' AND record.state = '在借';
这条 SQL 语句使用了三个表的连接,以查询借阅记录表中读者姓名为“郭玉姣”且当前状态为“在借”的记录,然后通过连接读者表和图书表,查询出对应的图书名称。
阅读全文