
select ql_cur1 from tf_ql_z where ql_no=b.ql_no and itm='5'
)
begin
return 结果
end
else if
exists(
select ql_cur3 from tf_ql_z where ql_no=b.ql_no and itm='5'
)
begin
return 结果
end
就这样写
需要准备的材料分别是:电脑、sql查询器。
1、首先,打开sql查询器,连接上相应的数据库表,以stu2表查询age>10的数据为例。
2、点击“查询”按钮,输入:select id, IF(sex=1, '男', '女') as sex from stu2 where age >5。
3、点击“运行”按钮,此时用where查询出了age>5的数据,并且之后用了if条件判断性别。
SQL语句中是没有if....else...语句的,但可以用case语句代替,而且是所有数据库都支持的,效果和if语句一样,都是表示条件。具体使用语法如下:
case when 条件1,
then 结果1;
when 条件2 ,
then 结果2 ;
else 结果N ,end。
可以有任意多个条件,如果没有默认的结果,最后的else也可以不写。
例如:select case when col1 >1 then col2 else col3 end from XXXtable
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)