现在有一张表,假设有 A B C D 几个字段假设这张表里边有 100条数据1, 3, 3, 42, 3,3,43, 3,3,44, 3,3,45, 3,3,4.....有个需求:如果 A>B的情况下 有个自定义变量 X 设为1否则X设为0大概就是 select * ,X from Table where A>B ....这个sql 能写出来么? 不需要存储过程,就是用sql实现.最后的结果大概是这样的A,B,C,D, X1, 3,3,4 , 02, 3,3,4 , 03, 3,3,4 , 04, 3,3,4, 15, 3,3,4, 1
from tb
select *,A>B as X from Table
add column X boolean;
update table_name set X=true where A>B;
update table_name set X=false where A<=B;