要求在规定时间内写完,提交到HR给的邮箱,题目信息和解答如下
题目:
题解:
1、使用sql选出下表中6个指标中至少4个指标大于50的城市
– 1.使用sql选出下表中6个指标中至少4个指标大于50的城市
select city
from (select t.city city,
case when oc>50 then 1 else 0 end n1,
case when sc>50 then 1 else 0 end n2,
case when pc>50 then 1 else 0 end n3,
case when hc>50 then 1 else 0 end n4,
case when gc>50 then 1 else 0 end n5,
case when ghc>50 then 1 else 0 end n6
from t_city t) c
where (c.n1+c.n2+c.n3+c.n4+c.n5+c.n6)>=4;
– 自变量计数版
select city,(c.n1+c.n2+c.n3+c.n4+c.n5+c.n6) m
from (select t.city,s.n n,
case when oc>50 then n+1 else 0 end n1,
case when sc>50 then n+1 else 0 end n2,
case when pc>50 then n+1 else 0 end n3,
case when hc>50 then n+1 else 0 end n4,
case when gc>50 then n+1 else 0 end n5,
case when ghc>50 then n+1 else 0 end n6
from t_city t
join (select city,0 n from t_city) s on t.city=s.city) as c
where (c.n1+c.n2+c.n3+c.n4+c.n5+c.n6)>=4
2、使用sql 选出下表中每个type指标 value值最大的前两个城市
– 2.使用sql 选出下表中每个type指标 value值最大的前两个城市
select type,substring_index(group_concat(city order by value desc),‘,’,2) city
from t_tv
group by type;
3、使用sql根据表A 表B 计算出表C (要求两种方法)
3.使用sql根据表A 表B 计算出表C (要求两种方法)
方法一
select t.date,t.v1,t.v2 from
(select a.date,v1,v2
from a join b on a.date=b.date
union all
select distinct a.date,v1,0
from a join b
where a.date not in (select date from b)
union all
select distinct b.date,0,v2
from a join b
where b.date not in (select date from a)) as t
order by length(t.date),t.date;
方法二
select t.date,t.v1,t.v2 from
(select a.date,v1,coalesce(v2,0) v2
from a left join b on a.date=b.date
union
select b.date,coalesce(v1,0) v1,v2
from a right join b on a.date=b.date) as t
order by length(t.date),t.date;
测试数据:
/*
Navicat Premium Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 50556
Source Host : localhost:3306
Source Schema : examdb
Target Server Type : MySQL
Target Server Version : 50556
File Encoding : 65001
Date: 08/01/2020 15:13:31
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
– Table structure for t_city
DROP TABLE IF EXISTS t_city
;
CREATE TABLE t_city
(
city
varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘城市名称’,
oc
int(11) NULL DEFAULT NULL,
sc
int(11) NULL DEFAULT NULL,
pc
int(11) NULL DEFAULT NULL,
hc
int(11) NULL DEFAULT NULL,
gc
int(11) NULL DEFAULT NULL,
ghc
int(11) NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
– Records of t_city
INSERT INTO t_city
VALUES (‘青岛’, 96, 50, 56, 55, 43, 21);
INSERT INTO t_city
VALUES (‘北京’, 74, 16, 96, 29, 54, 4);
INSERT INTO t_city
VALUES (‘南京’, 5, 52, 18, 82, 18, 83);
SET FOREIGN_KEY_CHECKS = 1;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
– Table structure for t_tv
DROP TABLE IF EXISTS t_tv
;
CREATE TABLE t_tv
(
city
varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘城市名称’,
type
varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘指标’,
value
int(11) NULL DEFAULT NULL COMMENT ‘值’
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
– Records of t_tv
INSERT INTO t_tv
VALUES (‘青岛’, ‘v_3’, 4);
INSERT INTO t_tv
VALUES (‘北京’, ‘v_1’, 94);
INSERT INTO t_tv
VALUES (‘南京’, ‘v_1’, 27);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
最后
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
=“https://img-blog.csdnimg.cn/img_convert/f2dc09f00f9d5465517e11808b217656.jpeg” alt=“img” style=“zoom: 33%;” />
最后
[外链图片转存中…(img-Aqix7w9o-1713473650396)]
[外链图片转存中…(img-YhTs0xBY-1713473650396)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!