面试高频sql问题

第一题:
面试高频sql问题

create table demo1(
rq date,
shfu VARCHAR(20)
);
insert into demo1(rq,shfu) VALUES
('2005-05-09','胜'),
('2005-05-09','胜'),
('2005-05-09','负'),
('2005-05-09','负'),
('2005-05-10','胜'),
('2005-05-10','负'),
('2005-05-10','负');
select * from demo1;

select rq,count(case shfu when '胜' then 1 end) as 胜,count(case shfu when '负' then 1 end) as 负 from demo1 GROUP BY rq

面试高频sql问题
第二题:
面试高频sql问题面试高频sql问题

create table demo2(
yuw int,
shx int,
yy int
);

INSERT INTO demo2(yuw,shx,yy) VALUES
(70,80,58)
SELECT * from demo2

select (case when yuw>=80 then '优秀' when yuw>=60 and yuw<80 then'及格' else '不及格' end ) as 语文, 
(case when shx>=80 then '优秀' when shx>=60 and shx<80 then'及格' else '不及格' end ) as 数学,
(case when yy>=80 then '优秀' when yy>=60 and yy<80 then'及格' else '不及格' end ) as 英语

面试高频sql问题
第三题:
面试高频sql问题

create table demo3(
id int PRIMARY key AUTO_INCREMENT,
rq date,
pm VARCHAR(20),
shl int
)
INSERT INTO demo3(rq,pm,shl) VALUES
('2005-05-12','火腿肠',500),
('2005-05-12','方便面',100),
('2005-05-12','方便面',200),
('2005-05-13','矿泉水',200),
('2005-05-13','可乐',150),
('2005-05-14','可乐',50),
('2005-05-14','矿泉水',300)
select * from demo3
#1.各种商品共有多少 最大一笔和最小一笔入库分别是多少
select pm,count(pm), max(shl),min(shl) FROM demo3 GROUP BY pm

面试高频sql问题

 #2.显示各种物品最后一次记录
select pm,max(rq) from demo3 GROUP BY pm  

面试高频sql问题
第四题
面试高频sql问题
面试高频sql问题

create table AAA(
mc VARCHAR(20),
sl int
)
create table BBB(
mc VARCHAR(20),
sl int
)

INSERT into AAA(mc,sl) VALUES
('A',100),
('B',120)
insert into BBB(mc,sl) VALUES
('A',10),
('A',20),
('B',10),
('B',20),
('B',30)
select * from AAA
select * from BBB

#用一条sql语句算出商品A,B还剩多少
select a.mc,a.sl-(select sum(b.sl) from BBB b WHERE b.mc= a.mc) as sl from AAA a GROUP BY a.mc

第五题:
面试高频sql问题

#sql语句计算SPH00017453 + 5000的结果SPH00022453 怎么写
select concat(substring('SPH00017453',1,6),17453+5000)```

上一篇:C# 获取电脑信息


下一篇:使用Arthas实现热更新