sql if用法?

sql if用法?

举报|  2009-04-16 10:50 yuzhan_hai  |  浏览 7050 次
有一张表rbb 里面有scsj,ty,yy
把整张表输出 select * from rbb,我现在想输出时进行筛选 scsj<>24时TY等于空SCSJ=24时TY等于原有数值不变,其它都不变输出整张表!
下面的几个我都试了 说是少关键字 运行不了 这是为什么呢
2009-04-16 11:04 提问者采纳
sql的select里没有if else,有类似的case when then else end 
------------------- 
select 
scsj, 
case scsj when 24 then ty 
else null end as ty, 
yy from rbb
提问者评价
select scsj, case scsj when 24 then ty else null end as ty, yy from rbb
评论(3)  |  5  4
2015-9-16 20:38 得時勿失
sql里面谁说没有if,孤陋寡闻还点赞 回复
2011-7-19 14:35 lemonzone2010
case when x=y then x when x>y then y else x end 回复
2010-9-11 17:51 x60024577
select scsj,(case when scsj<>24 then null when scsj=24 then ty) ty,yy from rbb 回复

lxm19872006 | 六级 采纳率40%

擅长: 百度空间

为您推荐:

按默认排序 | 按时间排序

其他3条回答

2009-04-16 10:53 俄尔普斯  | 八级
if 是在存储过程中用的
在sql 中你可以用case 效果一样
例子:
select * from rbb
where case when scsj <> 24 then ty = null
else scsj = 24 then ty
end
评论  |  0  0
2009-04-16 10:52 qq82557566  | 六级
if sc>24
begin
select * from rbb
end
此上是查询sc大于24的数据。。 
后面的一样。。。
评论  |  0  2
2009-04-16 10:58 javagarden  | 九级
select * from rbb 
where case when scsj <> 24 then ty = null 
else scsj = 24 then ty 
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值