sql - 谁能帮我解决这个 SQL 代码错误?
问题描述
谁能帮我解决这个错误?
数据库信息:
CREATE DATABASE School;
用于School
创建第一个表:
CREATE TABLE Classes
(
class_id INT,
name Varchar(45),
dept Char(4),
number CHAR(4),
section Char(2),
location Varchar(45),
meeting_time varchar(45),
PRIMARY KEY(class_id)
);
INSERT INTO Classes
VALUES (000001, 'Intro. to databases', 'info', '1620', '1a', 'sarpy214', 'm/w 1-2:45 pm');
INSERT INTO Classes (class_id, name, dept, number, section, location)
VALUES (000002, 'intro. to sql', 'info', '2630', 'ww', 'online');
INSERT INTO Classes
VALUES (000003, 'Software Engineering I', 'info', '1325', '4c', 'socmahoney205', 't/h 10-11:45 pm');
INSERT INTO Classes (class_id, name, dept, number, section, location)
VALUES (000004, 'Software Engineering II', 'info', '1335', 'ww', 'online');
INSERT INTO Classes
VALUES (000005, 'How to leave the shire & live forever', 'ring', '1001', '1r', 'socmahoney214', 'f 10-11:45 am');
INSERT INTO Classes (class_id, name, dept, number, section, location)
VALUES (000006, 'Living with the demon inside', 'psyc', '1668', 'ww', 'online');
INSERT INTO Classes
VALUES (000007, 'Internet Scripting jedi mastery', 'info', '2430', '2b', 'socmahoney205', 'm/w 10-11:45 am');
UPDATE Classes
SET meeting_time = 't/h 10-11:45 am'
WHERE class_id = 000003;
SELECT * FROM Classes;
现在创建第二个表:
CREATE TABLE Enrol
(
stu_id int,
class_id int,
grade char(1),
PRIMARY KEY (stu_id),
FOREIGN KEY (stu_id) REFERENCES Students(Stu_id),
FOREIGN KEY (class_id) REFERENCES Classes(class_id)
);
INSERT INTO Enrol VALUES (0000001, 000002, 'A');
INSERT INTO Enrol (stu_id, class_id) VALUES (0000002, 000002);
INSERT INTO Enrol VALUES (0000005, 000001, 'D');
INSERT INTO Enrol (stu_id, class_id) VALUES (0000006, 000005);
INSERT INTO Enrol VALUES (0000003, 000006, 'C');
SELECT * FROM Enrol;
创建第三个表:
CREATE TABLE Students
(
Stu_id INT PRIMARY KEY,
fname VARCHAR(45),
lname VARCHAR(45),
area_code CHAR(3),
phone VARCHAR(8)
);
INSERT INTO Students
VALUES (000001, 'patty', 'melt', '402', '234-9876');
INSERT INTO Students
VALUES (000002, 'bill', 'fold', '402', '531-6222');
INSERT INTO Students
VALUES (000003, 'sam', 'winchester', '402', '234-2346');
INSERT INTO Students
VALUES (000004, 'luke', 'skywalker', '402', '543-1234');
INSERT INTO Students
VALUES (000005, 'charlie', 'kelly', '402', '234-6859');
INSERT INTO Students
VALUES (000006, 'bilbo', 'baggins', '531', '646-3828');
SELECT * FROM Students
解决方案
您使用聚合函数并在组中的问题需要将所有非聚合函数
所以添加到组中
GROUP BY S.STU_ID, S.FNAME, S.LNAME;
推荐阅读
- angular - Defining type of variable as number does not throw error even if value is string --TypeScript, Angular
- ruby-on-rails - Rails - Multiple Select Update all objects of model
- wordpress - Wordpress:由于本地主机上的 Duplicator 插件,媒体文件 URL 损坏
- spring - 字段注入时的循环依赖
- python - 解压元组时输入提示?
- java - 从 XMLnode 读取值
- java-money - org.javamoney.moneta.RoundedMoney - 某些操作会产生舍入值,有些则不会
- javascript - javascript 为对象添加新属性
- visual-studio-2017 - 添加服务引用在 VS2017 中不起作用
- python - tf.train.import_meta_graph():无法加载一些变量值