有表A如下,条数会很多。id emp_id name kind update_time
1 1 test1 1 2011-07-25 08:45:14.921
2 1 test2 1 2011-07-26 08:46:14.921
3 1 test3 2 2011-07-27 08:47:14.921
4 2 test4 3 2011-07-28 08:48:14.921
5 2 test5 3 2011-07-29 08:49:14.921 想查询得到这样的结果
emp_id name kind update_time
1 test1 1 2011-07-25 08:45:14.921
1 test1 5 2011-07-25 08:45:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
1 test2 1 2011-07-26 08:46:14.921
1 test2 1 2011-07-26 08:46:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
1 test3 2 2011-07-27 08:47:14.921
2 test4 3 2011-07-28 08:48:14.921
2 test4 5 2011-07-28 08:48:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
2 test5 3 2011-07-29 08:49:14.921 在empid=1的每两条数据多一条
在empid=2的每两条数据多一条
SQL文该怎么写呢??
1 1 test1 1 2011-07-25 08:45:14.921
2 1 test2 1 2011-07-26 08:46:14.921
3 1 test3 2 2011-07-27 08:47:14.921
4 2 test4 3 2011-07-28 08:48:14.921
5 2 test5 3 2011-07-29 08:49:14.921 想查询得到这样的结果
emp_id name kind update_time
1 test1 1 2011-07-25 08:45:14.921
1 test1 5 2011-07-25 08:45:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
1 test2 1 2011-07-26 08:46:14.921
1 test2 1 2011-07-26 08:46:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
1 test3 2 2011-07-27 08:47:14.921
2 test4 3 2011-07-28 08:48:14.921
2 test4 5 2011-07-28 08:48:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
2 test5 3 2011-07-29 08:49:14.921 在empid=1的每两条数据多一条
在empid=2的每两条数据多一条
SQL文该怎么写呢??
1 test1 1 2011-07-25 08:45:14.921
1 test1 5 2011-07-25 08:45:14.921 ---》两条之间插入 kind 为5 时间为上条记录时间
这是第2条记录插入?
union all
select id,emp_id,name,5,update_time from a
order by id,kind
from tb a
where exists
(select 1 from tb b where b.emp_id=a.emp_id and b.id=a.id+1)如果有检索条件tb b这个应该为 select id,emp_id,name,5,update_time from tb where 条件 as tt