序号 |
考点 |
链接 |
备注(公司、年份) |
0 |
学生成绩基本案例 |
见下 |
基本操作 |
1 |
查找某用户最近的10条交易记录 |
见下 |
招银java1面 |
0. 学生成绩基本案例
create table stusco (sno int not null,grade int,check (grade>0 and grade<100) );
show tables;
desc stusco;
ALTER TABLE `zzb_test`.`stusco` ADD PRIMARY KEY (`sno`);
insert into stusco (sno,grade) values(1,65);
insert into stusco (sno,grade) values(2,69);
insert into stusco (sno,grade) values(3,41);
insert into stusco (sno,grade) values(5,99);
insert into stusco (sno,grade) values(7,82);
insert into stusco (sno,grade) values(8,70);
insert into stusco (sno,grade) values(10,75);
insert into stusco (sno,grade) values(12,60);
insert into stusco (sno,grade) values(15,79);
insert into stusco (sno,grade) values(22,86);
insert into stusco (sno,grade) values(245,98);
insert into stusco (sno,grade) values(234,92);
insert into stusco (sno,grade) values(113,55);
insert into stusco (sno,grade) values(199,68);
insert into stusco (sno,grade) values(198,77);
insert into stusco (sno,grade) values(236,82);
insert into stusco (sno,grade) values(240,67);
insert into stusco (sno,grade) values(98,72);
insert into stusco (sno,grade) values(137,66);
insert into stusco (sno,grade) values(145,73);
update stusco set grade=95 where sno=5;
select sno as 学生学号,grade as 学生成绩 from stusco where sno in (1,3,5,7,8,10,12,22);
select sno from stusco where grade > (select max(grade) from stusco where sno in (1,3,5,7,8,10,12,22));
select ss.sno,
(case
when ss.grade is null then '缺考'
when ss.grade <60 then '不及格'
when ss.grade >=60 and ss.grade< 70 then '及格'
when ss.grade >=70 and ss.grade<80 then '中'
when ss.grade >=80 and ss.grade<90 then '良'
when ss.grade >=90 and ss.grade <100 then '优'
else '什么鬼分数?'
end
)qualification
from stusco ss;
select
(case
when ss.grade is null then '缺考'
when ss.grade <60 then '不及格'
when ss.grade >=60 and ss.grade< 70 then '及格'
when ss.grade >=70 and ss.grade<80 then '中'
when ss.grade >=80 and ss.grade<90 then '良'
when ss.grade >=90 and ss.grade <100 then '优'
else '什么鬼分数?'
end
)qualification
,count(ss.sno) as stuNum from stusco ss
group by
case
when ss.grade is null then '缺考'
when ss.grade <60 then '不及格'
when ss.grade >=60 and ss.grade< 70 then '及格'
when ss.grade >=70 and ss.grade<80 then '中'
when ss.grade >=80 and ss.grade<90 then '良'
when ss.grade >=90 and ss.grade <100 then '优'
else '什么鬼分数?'
end;
select ss.sno
from stusco ss order by ss.sno;
group by
case
when ss.grade is null then '缺考'
when ss.grade <60 then '不及格'
when ss.grade >=60 and ss.grade< 70 then '及格'
when ss.grade >=70 and ss.grade<80 then '中'
when ss.grade >=80 and ss.grade<90 then '良'
when ss.grade >=90 and ss.grade <100 then '优'
else '什么鬼分数?'
end as qualification;
1.查找某用户最近的10条交易记录
with Sold as (
select row_number() over(partition by 编号 order by 销售时间 desc) rn , * from Sold
)
select * from Sold where rn <= 10