导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

判断语句能用sql语句来表达嘛

飞一龙 2007-12-25 10:00:07
IF(A1<5000,
A1*0.05,
IF(A1<=10000,A1*0.1-250,
IF(A1<=30000,A1*0.2-1250,
IF(A1<=50000,A1*0.3-4250,
IF(50000<=A1,A1*0.35-6750)))))

能用SQL表达出来嘛?
...全文
69 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pt1314917 2007-12-26
用case
回复
云中客 2007-12-26
case when /if else
回复
JL99000 2007-12-26
1 t_sql:用case when
2 如果用存储过程的话也可以用if else
回复
dmarkplus 2007-12-25

USE pubs
GO
SELECT Category =
CASE type
WHEN 'popular_comp' THEN 'Popular Computing'
WHEN 'mod_cook' THEN 'Modern Cooking'
WHEN 'business' THEN 'Business'
WHEN 'psychology' THEN 'Psychology'
WHEN 'trad_cook' THEN 'Traditional Cooking'
ELSE 'Not yet categorized'
END,
CAST(title AS varchar(25)) AS 'Shortened Title',
price AS Price
FROM titles
WHERE price IS NOT NULL
ORDER BY type, price
COMPUTE AVG(price) BY type
GO
回复
dawugui 2007-12-25
具体的>,>=,<,<=由你的数据而定.
回复
dawugui 2007-12-25
case when A1 < 5000 then A1*0.05
when A1 > 5000 and A1 <= 10000 then A1*0.1-250
when A1 > 10000 and A1 <= 30000 then A1*0.2-1250
when A1 > 30000 and A1 <= 50000 then A1*0.3-4250
when A1 > 50000 then A1*0.35-6750
end
回复
dawugui 2007-12-25
case when
回复
正牌风哥 2007-12-25
有不确定因素时else, case when ....then .. when .. then .. else .. end
回复
正牌风哥 2007-12-25
case when A1 <5000 then A1*0.05 when ....then ...end
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告