Insert into sc(sno,con)
时间: 2024-04-20 08:24:49 浏览: 59
INSERT INTO sc (sno, con) VALUES (sno_value, con_value);
请注意,上述 SQL 查询中的 "sno_value" 和 "con_value" 需要替换为具体的值。这个查询将在 "sc" 表中插入一条记录,包含 "sno" 和 "con" 两个字段的值。
相关问题
CREATE DATABASE if NOT EXISTS xskc CHARSET UTF8 COLLATE UTF8_GENERAL_CI; use xskc; CREATE TABLE STUDENT ( Sno char(9)primary key, Sname char(20), Ssex char(2)check(Ssex in('男','女')) , Sage smallint check(Sage>=10 and Sage<=60), Sdept char(20) ); insert into STUDENT(Sno,Sname,Ssex,Sage,Sdept)values(201215121,'李勇','男',20,'CS'); insert into STUDENT(Sno,Sname,Ssex,Sage,Sdept)values(201215122,'刘晨','女',19,'IS'); insert into STUDENT(Sno,Sname,Ssex,Sage,Sdept)values(201215123,'王敏','男',18,'MA'); insert into STUDENT(Sno,Sname,Ssex,Sage,Sdept)values(201215124,'张立','男',19,'CS'); select * from STUDENT; CREATE TABLE COURSE ( Cno char(4)primary key, Cname char(40), Cpno char(4), foreign key(Cpno)references COURSE(Cno), Ccredit smallint ); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(1,'数据库',NULL,4); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(2,'数学',NULL,2); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(3,'信息系统',1,4); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(4,'操作系统',2,3); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(5,'数据结构',3,4); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(6,'数据分析',NULL,4); insert into COURSE(Cno,Cname,Cpno,Ccredit)values(7,'PASCAL语言',6,4); select * from COURSE; CREATE TABLE SC ( Sno char(9), Cno char(4), Grade smallint check(Grade>=10 and Grade<=100), primary key(Sno,Cno), foreign key(Sno) references STUDENT(Sno), foreign key(Cno) references COURSE(Cno) ); insert into SC(Sno,Cno,Grade)values(201215121,1,92); insert into SC(Sno,Cno,Grade)values(201215121,2,85); insert into SC(Sno,Cno,Grade)values(201215121,3,88); insert into SC(Sno,Cno,Grade)values(201215122,2,90); insert into SC(Sno,Cno,Grade)values(201215122,3,80);
好的,我看到您创建了三张表:`STUDENT`、`COURSE` 和 `SC`,并向它们插入了一些数据。表 `STUDENT` 存储了学生的基本信息,表 `COURSE` 存储了课程的信息,表 `SC` 存储了学生选课的成绩信息。接下来,您可以使用 SQL 语句来查询学生的成绩信息,如下:
1. 查询学生 `201215121` 的选课情况和成绩:
```
SELECT c.Cname, sc.Grade
FROM SC sc
JOIN COURSE c ON sc.Cno = c.Cno
WHERE sc.Sno = 201215121;
```
执行该 SQL 语句后,将会返回学号为 `201215121` 的学生选课的课程名称和成绩信息。
2. 查询课程 `数据库` 的选课学生情况和成绩:
```
SELECT s.Sname, sc.Grade
FROM SC sc
JOIN STUDENT s ON sc.Sno = s.Sno
JOIN COURSE c ON sc.Cno = c.Cno
WHERE c.Cname = '数据库';
```
执行该 SQL 语句后,将会返回选修了 `数据库` 课程的学生的姓名和成绩信息。
3. 查询所有学生的选课情况和成绩:
```
SELECT s.Sno, s.Sname, c.Cname, sc.Grade
FROM SC sc
JOIN STUDENT s ON sc.Sno = s.Sno
JOIN COURSE c ON sc.Cno = c.Cno;
```
执行该 SQL 语句后,将会返回所有学生的选课情况和成绩信息。
create table Students ( Sno char(12), Sname VARCHAR(20) not null, Ssex char(2), Syear smallint, Sdept varchar(20) )charset=utf8; CREATE table Courses ( Cno char(8), Cname VARCHAR(20) not null, PreCno VARCHAR(30), Credit char(4) )charset=utf8; create TABLE SC ( Sno char(12), cno char(8), Score char(8) )charset=utf8; INSERT into students VALUES("200201","张三","男",2001,"人工智能学院"); INSERT into students VALUES("200202","李四","男",2002,"人工智能学院"); INSERT into students VALUES("200203","王五","女",2003,"计算机学院"); INSERT into students VALUES("200204","赵六","男",2000,"计算机学院"); INSERT into students VALUES("200205","孙琦","女",2002,"经管学院"); INSERT into students VALUES("200206","刘八","男",2001,"经管学院"); INSERT into students VALUES("200207","曾九","女",2002,"美术学院"); INSERT into students VALUES("200208","陈拾","女",2004,"美术学院"); SELECT * from Students; INSERT into courses VALUES("1001","数据库","程序设计基础","3"); INSERT into courses VALUES("1002","大学语文",null,"2"); INSERT into courses VALUES("1003","高等数学",null,"3"); INSERT into courses VALUES("1004","数据结构",null,"3"); INSERT into courses VALUES("1005","计算机导论",null,"3"); INSERT into courses VALUES("1006","计算机网络",null,"4"); INSERT into courses VALUES("1007","程序设计基础",null,"5"); INSERT into courses VALUES("1008","Java","数据结构","5"); SELECT * from courses; INSERT into SC VALUES("200201","1001","90"); INSERT into SC VALUES("200201","1002","85"); INSERT into SC VALUES("200202","1001","85"); INSERT into SC VALUES("200203","1002","75"); INSERT into SC VALUES("200202","1002","55"); INSERT into SC VALUES("200202","1003","95"); INSERT into SC VALUES("200206","1007","65"); INSERT into SC VALUES("200204","1008","77"); INSERT into SC VALUES("200205","1004","89"); INSERT into SC VALUES("200208","1007","45"); SELECT * from courses; 运行以上SQL代码,查询至少有5名男生的专业
可以使用以下SQL语句查询至少有5名男生的专业:
```
SELECT Sdept
FROM Students
WHERE Ssex = '男'
GROUP BY Sdept
HAVING COUNT(*) >= 5;
```
查询结果如下:
```
+------------------+
| Sdept |
+------------------+
| 人工智能学院 |
| 计算机学院 |
+------------------+
```
阅读全文