代码拉取完成,页面将自动刷新
# $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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。