+ -
当前位置:首页 → 问答吧 → 用sql语句等分数据表中每列相邻值并存储

用sql语句等分数据表中每列相邻值并存储

时间:2011-11-10

来源:互联网

请高手赐教,谢谢!
有NO表,把NO表中NUM0、NUM1、NUM2列的前后两个数据五等分得到NO’表。例如:
NO表
NUM0 NUM1 NUM2
50 10 300
100 15 200
150 5 260
… … …



NO’表
NUM0 NUM1 NUM2
50 10 300
60 11 280
70 12 260
80 13 240
90 14 220
100 15 200
110 13 212
120 11 224
130 9 236
140 7 248
150 5 260
… … …

作者: sxldxx   发布时间: 2011-11-10

这是等分么?
SQL code
create table tb(NUM0 int,NUM1 int,NUM2 int)
insert into tb select 50,10,300
insert into tb select 100,15,200
insert into tb select 150,5,260
go
select a.num0+10*b.number num0,a.num1,a.num2-10*b.number num2
from tb a,master..spt_values b
where b.type='p' and b.number between 1 and 5
/*
num0        num1        num2
----------- ----------- -----------
60          10          290
70          10          280
80          10          270
90          10          260
100         10          250
110         15          190
120         15          180
130         15          170
140         15          160
150         15          150
160         5           250
170         5           240
180         5           230
190         5           220
200         5           210

(15 行受影响)
*/
go
drop table tb

作者: qianjin036a   发布时间: 2011-11-10

SQL code
create table tb(NUM0 int,NUM1 int,NUM2 int)
insert into tb select 50,10,300
insert into tb select 100,15,200
insert into tb select 150,5,260
go
select a.num0+10*b.number num0,a.num1+b.number num1,a.num2-10*b.number num2
from tb a,master..spt_values b
where b.type='p' and b.number between 1 and 5
/*
num0        num1        num2
----------- ----------- -----------
60          11          290
70          12          280
80          13          270
90          14          260
100         15          250
110         16          190
120         17          180
130         18          170
140         19          160
150         20          150
160         6           250
170         7           240
180         8           230
190         9           220
200         10          210

(15 行受影响)
*/
go
drop table tb

作者: qianjin036a   发布时间: 2011-11-10