表student 有姓名、课程、成绩,三个字段,
课程名称未知,姓名对应的课程 成绩 也无知;
要求:查询所有成绩都大于等于90的姓名;
SELECT 姓名 from
(select 姓名,min(成绩) mincj from student GROUP BY 姓名) student
where mincj>=90;
SELECT distinct 姓名 from student t where not EXISTS(SELECT 姓名 from student WHERE 成绩<90 and 姓名=t.姓名);
SELECT distinct 姓名 from student t where 姓名 not in(SELECT 姓名 from student WHERE 成绩<90 and 姓名=t.姓名);
复习下常用语句:
create database 数据库名;
use 数据库名; --切换到你创建的数据库
create table 表名(
字段 数据类型 非空 自动增长
proId int not null auto_increment,
proName varchar(20) not null,
primary key PK_positon(proId)设置主键
)
drop table 表名;--删除表
CREATE TABLE student (姓名 VARCHAR(255),课程 VARCHAR(255),成绩 int(3));
INSERT INTO student (姓名,课程,成绩) VALUES('张三','数学',90);
INSERT Into student VALUES('李四','语文',95);
UPDATE student set 成绩=70 where 姓名='王麻子' and 成绩=98 and 课程='历史';
DELETE from student where 姓名='张三' and 课程='化学';
SELECT * from student;
Delete from tablename where 1=1 ---删除表中所有数据