当前位置:网站首页>Daily sql-employee bonus filtering and answer rate ranking first
Daily sql-employee bonus filtering and answer rate ranking first
2022-08-11 07:14:00 【Eating too much sugar will not gain weight】
每日sql 1-员工奖金
Ask for a bonus less than1000employee names and bonuses
DDL
Create table If Not Exists Employee (EmpId int, Name varchar(255), Supervisor int, Salary int);Create table If Not Exists Bonus (EmpId int, Bonus int);insert into Employee (EmpId, Name, Supervisor, Salary) values (3, 'Brad', null, 4000);insert into Employee (EmpId, Name, Supervisor, Salary) values (1, 'John', 3, 1000);insert into Employee (EmpId, Name, Supervisor, Salary) values (2, 'Dan', 3, 2000);insert into Employee (EmpId, Name, Supervisor, Salary) values (4, 'Thomas', 3, 4000);insert into Bonus (EmpId, Bonus) values (2, 500);insert into Bonus (EmpId, Bonus) values (4, 2000);
sql
select Employee.Name,Bonus.Bonus FROM Employee join Bonus on Employee.EmpId=Bonus.EmpId where Bonus.Bonus <1000 or Bonus.Bonus is null;
2-Find the question with the highest answer rate
A table records the presentation of each questionshow和回答answer状态,Use if no answerskip代替answer状态.Find the question with the highest answer rate
DDL
Create table If Not Exists survey_log (uid int, action varchar(255), question_id int, answer_id int, q_num int, timestamp int);insert into survey_log (uid, action, question_id, answer_id, q_num, timestamp) values (5, 'show', 285, null, 1, 123);insert into survey_log (uid, action, question_id, answer_id, q_num, timestamp) values (5, 'answer', 285, 124124, 1, '124');insert into survey_log (uid, action, question_id, answer_id, q_num, timestamp) values (5, 'show', 369, null, 2, 125);insert into survey_log (uid, action, question_id, answer_id, q_num, timestamp) values (5, 'skip', 369, null, 2, 126);
sql
select question_id
from survey_log
group by question_id
order by sum(case when action ="answer" then 1 else 0 end )/sum(case when action = "show" then 1 else 0 end) desc limit 1;
边栏推荐
猜你喜欢
随机推荐
HCIP-BGP的选路实验
OA项目之我的审批(查询&会议签字)
华为防火墙-3-应用过滤
TOP2 Add two numbers
HCIP OSPF dynamic routing protocol
bash的命令退出状态码
查看内核版本和发行版版本
HCIP WPN experiment
sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
命令输出给变量
ETCD Single-Node Fault Emergency Recovery
淘宝API常用接口与获取方式
numpy和tensor增加或删除一个维度
求过去半年内连续30天以上每天都有1000元以上成交的商铺
HCIA knowledge review
HCIP BGP built adjacent experiment
每日sql-统计各个专业人数(包括专业人数为0的)
每日sql-员工奖金过滤和回答率排序第一
MySQL导入导出&视图&索引&执行计划
每日sql-找到每个学校gpa最低的同学(开窗)