然后两个表对应的列进行比较取最小值存到表三
关键在这句啊,怎么比较,传说中的ifelse语句,拜托帮写一下,学习学习
连接不是问题,这样吧就当是一个表中两列的数据同行比较如何做来?
关键在这句啊,怎么比较,传说中的ifelse语句,拜托帮写一下,学习学习
连接不是问题,这样吧就当是一个表中两列的数据同行比较如何做来?
解决方案 »
- 求SQLServer2008输入一个农历日期然后自动换算成公历日期
- 请给一下sql 2005 开发版的补丁下载地址吧,
- 如何知道那些客户端的sql server 连接到了服务器端?
- 一个复制问题,复制时提示“不能大容量复制到表subfile(表名)”!
- NT AUTHORITY\NETWORK SERVICE默认的密码是什么
- 帮忙优化个语句
- sqlserver2000关于sp_OACreate的问题
- 能将列名不同但类型一样的值从另一个表中导入进来吗?
- 为什么exec sp_rename无法更改字段名?
- Delphi 5.0与 SQL Server 7.0的关于Image的问题,紧急求助!!!!
- 小问题
- 新浪网的论坛真差,发个帖子,再也找不到,什么鸡巴玩意儿
select a.id,timestamp_min=case when a.timestamp>=b.timestamp then b.timestamp else a.timestamp end
from table1 a inner join table2 b on a.id=b.id
from table1 full outer join table2 on
table1.id=table2.id
from
(
select * from table1
union all
select * from table2
)tt
group by id
select distinct isnull(a.id,b.id) as id ,(case when a.timestamp<b.timestamp then a.timestamp else b.timestamp end ) as timestamp_min
from table1 a full outer join table2 b on
a.id=b.id
insert table1
select 1,3
union select 2,5
union select 3,1
create table table2( id int, timestamp int)
insert table2
select 1, 2
union select 2 , 3
union select 3 , 4
union select 4 , 6 select id=isnull(a.id,b.id) ,timestamp_min=case when a.timestamp>=b.timestamp then b.timestamp else isnull(a.timestamp,b.timestamp) end
from table1 a full join table2 b on a.id=b.id---如果要插入到tabel3用这个
select id=isnull(a.id,b.id),timestamp_min=case when a.timestamp>=b.timestamp then b.timestamp else isnull(a.timestamp,b.timestamp) end into table3
from table1 a full join table2 b on a.id=b.idselect * from table3
---插入结束drop table table1,table2
from
(
select * from table1
union all
select * from table2
)tt
group by id这样就可以了吧?不用再连吧?
num = case WHEN a.num < b.num then a.num else b.num end
from table1 a full join table2 b on a.id =b.id
leo_lesley(leo)一贴已经搞定,初学sql见笑,下面还有这么多热心的朋友回啊,以后有问题还来这里问啊,哈哈,谢谢大家了