sql 查詢成績都大於等於90的姓名


表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 ---刪除表中所有數據


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM