日期:2014-05-18 浏览次数:21220 次
--在SQL SERVER 中就是个行转列
declare @T table (
序号 int,经度 int,纬度 int)
insert into @T
select 1,88,76 union all
select 2,89,76 union all
select 3,90,75 union all
select 4,77,90 union all
select 5,78,91 union all
select 6,79,90
select
min(序号) as 序号,
max(case when 序号%3=1 then 经度 else 0 end) as 经度1,
max(case when 序号%3=1 then 纬度 else 0 end) as 纬度1,
max(case when 序号%3=2 then 经度 else 0 end) as 经度2,
max(case when 序号%3=2 then 纬度 else 0 end) as 纬度2,
max(case when 序号%3=0 then 经度 else 0 end) as 经度3,
max(case when 序号%3=0 then 纬度 else 0 end) as 纬度3
from @T group by ceiling(序号/3.0)
/*
序号 经度1 纬度1 经度2 纬度2 经度3 纬度3
----------- ----------- ----------- ----------- ----------- ----------- -----------
1 88 76 89 76 90 75
4 77 90 78 91 79 90
*/
------解决方案--------------------
转换按钮事件就是换一下数据即可。
--转换前的数据
select * from tablename
--转换后的数据
select
min(序号) as 序号,
max(case when 序号%3=1 then 经度 else 0 end) as 经度1,
max(case when 序号%3=1 then 纬度 else 0 end) as 纬度1,
max(case when 序号%3=2 then 经度 else 0 end) as 经度2,
max(case when 序号%3=2 then 纬度 else 0 end) as 纬度2,
max(case when 序号%3=0 then 经度 else 0 end) as 经度3,
max(case when 序号%3=0 then 纬度 else 0 end) as 纬度3
from tablename group by ceiling(序号/3.0)