select id from t1 order by idid
200702
200702
200704
200704
200705查询结果如上
我想变成如下结果
id
标项1
标项1
标项2
标项2
标项3
......以此类推
200702
200702
200704
200704
200705查询结果如上
我想变成如下结果
id
标项1
标项1
标项2
标项2
标项3
......以此类推
解决方案 »
- 如何快速熟悉数据库中这表的作用和关系
- 求一个视图或者函数
- 关于MSDE的实例安装问题
- *****大侠求救,通过SQL Query如何查找"TCP/IP"端口号???????
- sql server 2000 raid 10 写入性能极其低下,求出主意
- 怎么可以最简单的得到某个SQL语句中的某个字段中的值是否全部相同?
- 请问:sql server 如何查看自增变量的当前值???
- 如何用过程调度的求。。。。?
- 这个两层递归的语句该怎么写?
- 高手请进。。。。。。高难度问题。。。。。。请高手帮忙。。(急)。。谢谢
- 这样SQL语句可以实现么,不好意思只有10分了
- 文章系统,查询所有类别下的一条最新文章,sql要怎么写啊?
'标项'+cast((select count(distinct id) from t1 where id<=a.id) as varchar) as id
from t1 a
order by id
from 表名Aupdate 表名A
set id='标项'+rtrim(a.con)
from # a where a.id=表名A.id
查询:
select * from 表名A
insert @t select '200702'
union all select '200702'
union all select '200704'
union all select '200704'
union all select '200705'select '标项'+rtrim((select count(distinct id) from @t where id<=a.id)) from @t a--结果
----------------
标项1
标项1
标项2
标项2
标项3(所影响的行数为 5 行)
alter table ta add con int null
declare @i int
set @i=0
udpate ta
set con=@i,@i=@i+1update ta
set id='标项'+rtrim(con)查询:
select * from 表名A
alter table ta add con int null 新增递增列
declare @i int
set @i=0
udpate ta
set con=@i,@i=@i+1update ta
set id='标项'+(select rtrim(count(distinct id)) from ta where con!>a.con)
from ta aalter table ta drop column con --删除新增递增列select * from ta
select bdp_name,bdp_pinpai,bdp_bz,bdp_unit,bdp_num,yqghsj,bdp_desc,bdp_fzid from bid_item a inner join bid_detailed_plan b on a.bi_id=b.bdp_pid where a.bi_id = '"&bi_id&"' order by bdp_fzid查询结果大意
字段1 2 3 4 .... bdp_fzid
123 123 123 123 200702
123 123 123 123 200702
123 123 123 123 200703
123 123 123 123 200703
123 123 123 123 200705
123 123 123 123 200705
123 123 123 123 200706想得到这样
字段1 2 3 4 .... bdp_fzid
123 123 123 123 标项1
123 123 123 123 标项1
123 123 123 123 标项2
123 123 123 123 标项2
123 123 123 123 标项3
123 123 123 123 标项3
123 123 123 123 标项4
123 123 123 123 标项2
123 123 123 123 标项2
123 123 123 123 标项3
123 123 123 123 标项3
123 123 123 123 标项4
123 123 123 123 标项4
123 123 123 123 标项5
为什么是2开始而不是一开始?
insert T select 123, '200702'
union all select 123, '200702'
union all select 123, '200703'
union all select 123, '200703'
union all select 123, '200705'
union all select 123, '200705'
union all select 123, '200706'declare @col1 int, @col2 varchar(10), @col2_old varchar(10), @id int
declare @t table(col1 int, col2 varchar(10))declare cur cursor local
for
select * from T
open curfetch next from cur into @col1, @col2
select @col2_old=@col2, @id=1
while @@fetch_status=0
begin
if @col2_old=@col2
insert @t select @col1, '标项'+rtrim(@id)
else
begin
select @id=@id+1, @col2_old=@col2
insert @t select @col1, '标项'+rtrim(@id)
end fetch next from cur into @col1, @col2
endclose cur
deallocate curselect * from @t--result
col1 col2
----------- ----------
123 标项1
123 标项1
123 标项2
123 标项2
123 标项3
123 标项3
123 标项4(7 row(s) affected)