create table t
(id int,
time1 varchar(20),
time2 varchar(20)
)
insert t
select 1,'2011-06-02 16:10:10','2011-06-02 16:30:20' union all
select 2,'2011-06-02 16:40:10','2011-06-02 17:21:20' union all
select 3,'2011-06-02 17:30:10','2011-06-02 18:20:20' union all
select 4,'2011-06-02 18:40:10','2011-06-02 19:45:20' 要求:time2减time1的时间小于15分钟计0个小时,大于等于15分钟小于30分钟计0.25个小时,大于等于30分钟小于45分钟计0.5个小时,大于等于45分钟小于60分钟计0.75个小时,大于等于60分钟小于75分钟计1个小时,依此类推以上的结果为:
1 0.15
2 0.5
3 0.75
4 1
(id int,
time1 varchar(20),
time2 varchar(20)
)
insert t
select 1,'2011-06-02 16:10:10','2011-06-02 16:30:20' union all
select 2,'2011-06-02 16:40:10','2011-06-02 17:21:20' union all
select 3,'2011-06-02 17:30:10','2011-06-02 18:20:20' union all
select 4,'2011-06-02 18:40:10','2011-06-02 19:45:20' 要求:time2减time1的时间小于15分钟计0个小时,大于等于15分钟小于30分钟计0.25个小时,大于等于30分钟小于45分钟计0.5个小时,大于等于45分钟小于60分钟计0.75个小时,大于等于60分钟小于75分钟计1个小时,依此类推以上的结果为:
1 0.15
2 0.5
3 0.75
4 1
from t/**---------------------------------------
0.25
0.50
0.75
1.00(4 行受影响)
**/
id,
diff = CAST(DATEDIFF(MINUTE, time1, time2) / 15 * 0.25 AS FLOAT)
FROM #temp
/*
id diff
1 0.25
2 0.5
3 0.75
4 1
*/
create table t
(id int,
time1 varchar(20),
time2 varchar(20)
)
insert t
select 1,'2011-06-02 16:10:10','2011-06-02 16:30:20' union all
select 2,'2011-06-02 16:40:10','2011-06-02 17:21:20' union all
select 3,'2011-06-02 17:30:10','2011-06-02 18:20:20' union all
select 4,'2011-06-02 18:40:10','2011-06-02 19:45:20' select id,(datediff(minute,time1,time2)/15*0.25) as 你要的结果 from t
/*
id 你要的结果
----------- ---------------------------------------
1 0.25
2 0.50
3 0.75
4 1.00(4 row(s) affected)
*/
create table #t
(id int,
time1 varchar(20),
time2 varchar(20)
)
insert #t
select 1,'2011-06-02 16:10:10','2011-06-02 16:30:20' union all
select 2,'2011-06-02 16:40:10','2011-06-02 17:21:20' union all
select 3,'2011-06-02 17:30:10','2011-06-02 18:20:20' union all
select 4,'2011-06-02 18:40:10','2011-06-02 19:45:20'
select id,(datediff(ss,time1,time2)/900)*0.25 from #t
请问,从insert t这行开始就看不懂了,这是什么语句?