Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1440.test 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-04-10 23:34 +08:00 . 570-1264-1303-1440 (4)
# $1440. 计算布尔表达式的值
# https://leetcode-cn.com/problems/evaluate-boolean-expression/
# SQL架构
Create Table If Not Exists Variables (name varchar(3), value int);
Create Table If Not Exists Expressions (left_operand varchar(3), operator ENUM('>', '<', '='), right_operand varchar(3));
Truncate table Variables;
insert into Variables (name, value) values ('x', '66');
insert into Variables (name, value) values ('y', '77');
Truncate table Expressions;
insert into Expressions (left_operand, operator, right_operand) values ('x', '>', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('x', '<', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('y', '>', 'x');
insert into Expressions (left_operand, operator, right_operand) values ('y', '<', 'x');
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'x');
# Write your MySQL query statement below
select
e.left_operand as left_operand,
e.operator as operator,
e.right_operand as right_operand,
case
e.operator
when '>' then if(v1.value > v2.value, 'true', 'false')
when '<' then if(v1.value < v2.value, 'true', 'false')
else if(v1.value = v2.value, 'true', 'false')
end as value
from
Expressions e
left join Variables v1 on v1.name = e.left_operand
left join Variables v2 on v2.name = e.right_operand;
# clean-up
drop table Variables;
drop table Expressions;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助