gpt4 book ai didi

mysql - 错误代码 : 1052 Column 'admin_id' in field list is ambiguous

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:00 26 4
gpt4 key购买 nike

您好,我曾尝试在我的数据库中创建时间 TableView ,但我在使用 admin_id 列时遇到了问题。我正在重用另一个有效的作业中的代码,所以我很困惑为什么它不起作用。请帮助我!!!

选择语句

SELECT timesheet_id, class, day, hour, week, admin_id, date_added FROM timesheet, day, classes, admin
WHERE timesheet_id AND
classes.class_id = timesheet.class_id AND
day.day_id = timesheet.day_id AND
admin.admin_id = timesheet.admin_id ORDER BY timesheet.timesheet_id.;

数据库代码

'CREATE DATABASE /*!32312 IF NOT EXISTS*/`timesheet` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `timesheet`;

/*Table structure for table `admin` */

DROP TABLE IF EXISTS `admin`;

CREATE TABLE `admin` (
`admin_id` int(100) NOT NULL AUTO_INCREMENT,
`username` varchar(10) DEFAULT NULL,
`password` char(30) DEFAULT NULL,
PRIMARY KEY (`admin_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

/*Data for the table `admin` */

insert into `admin`(`admin_id`,`username`,`password`) values (1,'1627724','troll1'),(2,'1627406','troll2');

/*Table structure for table `classes` */

DROP TABLE IF EXISTS `classes`;

CREATE TABLE `classes` (
`class_id` int(11) NOT NULL AUTO_INCREMENT,
`class` varchar(30) DEFAULT NULL,
PRIMARY KEY (`class_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

/*Data for the table `classes` */

insert into `classes`(`class_id`,`class`) values (1,'Validate and Test'),(2,'Complex Web'),(3,'Advanced OO Web'),(4,'Project Management'),(5,'Project Web'),(6,'Meeting'),(7,'Study'),(8,'Software Development');

/*Table structure for table `day` */

DROP TABLE IF EXISTS `day`;

CREATE TABLE `day` (
`day_id` int(11) NOT NULL AUTO_INCREMENT,
`day` varchar(15) NOT NULL,
PRIMARY KEY (`day_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

/*Data for the table `day` */

insert into `day`(`day_id`,`day`) values (1,'Monday'),(2,'Tuesday'),(3,'Wednesday'),(4,'Thursday'),(5,'Friday'),(6,'Saturday'),(7,'Sunday');

/*Table structure for table `menu` */

DROP TABLE IF EXISTS `menu`;

CREATE TABLE `menu` (
`Menu_id` int(100) NOT NULL AUTO_INCREMENT,
`Menu` char(10) DEFAULT NULL,
PRIMARY KEY (`Menu_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

/*Data for the table `menu` */

insert into `menu`(`Menu_id`,`Menu`) values (1,'index'),(2,'contact us'),(3,'project'),(4,'timesheets');

/*Table structure for table `timesheet` */

DROP TABLE IF EXISTS `timesheet`;

CREATE TABLE `timesheet` (
`timesheet_id` int(11) NOT NULL AUTO_INCREMENT,
`class_id` int(11) NOT NULL,
`day_id` int(11) NOT NULL,
`hour` float DEFAULT NULL,
`week` varchar(8) NOT NULL,
`admin_id` int(11) NOT NULL,
`date_added` date NOT NULL,
PRIMARY KEY (`timesheet_id`),
KEY `class_fk` (`class_id`),
KEY `day_fk` (`day_id`),
KEY `admin_fk` (`admin_id`),
CONSTRAINT `admin_fk` FOREIGN KEY (`admin_id`) REFERENCES `admin` (`admin_id`),
CONSTRAINT `class_fk` FOREIGN KEY (`class_id`) REFERENCES `classes` (`class_id`),
CONSTRAINT `day_fk` FOREIGN KEY (`day_id`) REFERENCES `day` (`day_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
/*Data for the table `timesheet`'

insert into `timesheet`(`timesheet_id`,`class_id`,`day_id`,`hour`,`week`,`admin_id`,`date_added`) values (1,1,1,1,'week1',2,'2013-10-14'),(2,2,5,6,'week1',2,'2013-10-14'),(3,1,3,5,'week1',2,'2013-10-14'),(4,5,6,2,'week1',2,'2013-10-14'),(5,8,6,4,'week1',2,'2013-10-14');

最佳答案

这意味着在您的查询中访问的表中有多个名为 admin_id 的列,因此 mysql 不知道从哪一列返回结果。

更改您的选择语句以包括表别名(admin 或 timesheet),如下所示:SELECT timesheet_id, class, day, hour, week, ti​​mesheet.admin_id, date_added FROM timesheet

关于mysql - 错误代码 : 1052 Column 'admin_id' in field list is ambiguous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19351633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com