sql 求助

wranglergu 2012-03-14 11:02:48
select 1 as a,case 2 when 2 then 3 else 4 end as b,1*b as c


我想在字段c上用前面处理好的b字段,怎么使用呢。百度上实在不知道该怎么描述。所以....
...全文
78 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
super007007007 2012-03-14
  • 打赏
  • 举报
回复

;with temp as(select 1 as a,case 2 when 2 then 3 else 4 end as b)
select temp.*,temp.b * 1 as c from temp

wranglergu 2012-03-14
  • 打赏
  • 举报
回复
我的意思是,因为b字段处理的太麻烦,所以,想在c中直接使用处理之后的b就不用
select 1 as a,case 2 when 2 then 3 else 4 end as b,1*(case 2 when 2 then 3 else 4 end) as c

dawugui 2012-03-14
  • 打赏
  • 举报
回复
或者用子查询:
select t.* , b * 1 as c from
(...) t
dawugui 2012-03-14
  • 打赏
  • 举报
回复
[Quote=引用楼主 wranglergu 的回复:]
SQL code
select 1 as a,case 2 when 2 then 3 else 4 end as b,1*b as c


我想在字段c上用前面处理好的b字段,怎么使用呢。百度上实在不知道该怎么描述。所以....
[/Quote]

select 1 as a,case 2 when 2 then 3 else 4 end as b,
(case 2 when 2 then 3 else 4 end )*b as c
SqlServer2008 2012-03-14
  • 打赏
  • 举报
回复




select a,1*b as c from
(
select 1 as a,case 2 when 2 then 3 else 4 end as b from tab
) t
wranglergu 2012-03-14
  • 打赏
  • 举报
回复
可能没什么好办法了吧。

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧