首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

整个表的数据列出来的有关问题

2012-02-08 
整个表的数据列出来的问题?求一SQL:我想将整个表的数据列出来,tabletemp表中有id,flag,a,b,c,f字段,如果 f

整个表的数据列出来的问题?
求一SQL:
我想将整个表的数据列出来,tabletemp表中有id,flag,a,b,c,f字段,如果 flag='是' 执行 select a,b,b+c from tabletemp 如果flag='否' 执行 select a,b,b+f from tabletemp 列出全部表中的tabletemp中的数据并按id排序,这个语句怎么写?

[解决办法]
select a,b,b+c from tabletemp where flag = '是'
union all
select a,b,b+f from tabletemp where flag = '否'

[解决办法]

SQL code
select a , b , newcol = b+c from tabletemp where flag = '是' union  all select a , b , newcol = b+f from tabletemp where flag = '否'order by id
[解决办法]
select a,b,b+c from tabletemp where flag='是' 
union
select a,b,b+c from tabletemp flag='否' 
order by id
[解决办法]
SQL code
--一共三个,你看哪个合适?select a , b , newcol from(  select id , a , b , newcol = b+c from tabletemp where flag = '是'   union  all   select id , a , b , newcol = b+f from tabletemp where flag = '否') torder by id
[解决办法]
select a , b , newcol = b+ case when flag = '是' then c else f end
from tabletemp
[解决办法]
select a , b , newcol = b+ case when flag = '是' then c else f end
from tabletemp
order by id

热点排行