求助sql查询语句

sun485916 2009-11-18 11:23:55
a b c d e f g
100000.00 20000.00 80000.00 5 2009-11-18 00:00:00.000 16000.00 11
100000.00 20000.00 80000.00 5 2009-12-18 00:00:00.000 16000.00 11
100000.00 20000.00 80000.00 5 2010-01-18 00:00:00.000 16000.00 11
100000.00 20000.00 80000.00 5 2010-02-18 00:00:00.000 16000.00 11
100000.00 20000.00 80000.00 5 2010-03-18 00:00:00.000 16000.00 11

数据如上.
查询的时候我想添加一列FNO
显示的值是
FNO a b c d e f g
第1期 100000.00 20000.00 80000.00 5 2009-11-18 00:00:00.000 16000.00 11
第2期 100000.00 20000.00 80000.00 5 2009-12-18 00:00:00.000 16000.00 11
第3期 100000.00 20000.00 80000.00 5 2010-01-18 00:00:00.000 16000.00 11
第4期 100000.00 20000.00 80000.00 5 2010-02-18 00:00:00.000 16000.00 11
第5期 100000.00 20000.00 80000.00 5 2010-03-18 00:00:00.000 16000.00 11
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
icelovey 2009-11-18
  • 打赏
  • 举报
回复
一群强分狂@@@@@@@@@@@@@@
好汉坡 2009-11-18
  • 打赏
  • 举报
回复
select fno='第'+ltrim((select count(1) from @tb where e<=t.e))+'期',*
from @tb t

fno a b c d e f g
---------------- --------------------------------------- --------------------------------------- --------------------------------------- ----------- ----------------------- --------------------------------------- -----------
第1期 100000.00 20000.00 80000.00 5 2009-11-18 00:00:00.000 16000.00 11
第2期 100000.00 20000.00 80000.00 5 2009-12-18 00:00:00.000 16000.00 11
第3期 100000.00 20000.00 80000.00 5 2010-01-18 00:00:00.000 16000.00 11
第4期 100000.00 20000.00 80000.00 5 2010-02-18 00:00:00.000 16000.00 11
第5期 100000.00 20000.00 80000.00 5 2010-03-18 00:00:00.000 16000.00 11

(5 行受影响)
好汉坡 2009-11-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hero__stone 的回复:]
SQL code--> 测试数据: @tbdeclare@tbtable (a numeric(8,2),b numeric(7,2),c numeric(7,2),dint,edatetime,f numeric(7,2),gint)insertinto@tbselect100000.00,20000.00,80000.00,5,'2009-11-18 00:00:00.000',16000.0?-
[/Quote]
日,怎么我发的代码变成这样了?这是什么语言?
好汉坡 2009-11-18
  • 打赏
  • 举报
回复
--> 测试数据: @tb
declare @tb table (a numeric(8,2),b numeric(7,2),c numeric(7,2),d int,e datetime,f numeric(7,2),g int)
insert into @tb
select 100000.00,20000.00,80000.00,5,'2009-11-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2009-12-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-01-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-02-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-03-18 00:00:00.000',16000.00,11

select fno='第'+ltrim((select count(1) from @tb where e<=t.e))+'期',*
from @tb t

fno a b c d e f g
---------------- --------------------------------------- --------------------------------------- --------------------------------------- ----------- ----------------------- --------------------------------------- -----------
第1期 100000.00 20000.00 80000.00 5 2009-11-18 00:00:00.000 16000.00 11
第2期 100000.00 20000.00 80000.00 5 2009-12-18 00:00:00.000 16000.00 11
第3期 100000.00 20000.00 80000.00 5 2010-01-18 00:00:00.000 16000.00 11
第4期 100000.00 20000.00 80000.00 5 2010-02-18 00:00:00.000 16000.00 11
第5期 100000.00 20000.00 80000.00 5 2010-03-18 00:00:00.000 16000.00 11

(5 行受影响)
--小F-- 2009-11-18
  • 打赏
  • 举报
回复
----------------------------------------------------------------
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-11-18 11:25:54
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([a] numeric(8,2),[b] numeric(7,2),[c] numeric(7,2),[d] int,[e] datetime,[f] numeric(7,2),[g] int)
insert [tb]
select 100000.00,20000.00,80000.00,5,'2009-11-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2009-12-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-01-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-02-18 00:00:00.000',16000.00,11 union all
select 100000.00,20000.00,80000.00,5,'2010-03-18 00:00:00.000',16000.00,11
--------------开始查询--------------------------

select FNO='第'+cast(row_number()over(order by getdate()) as varchar)+'期',* from [tb]
----------------结果----------------------------
/*
(5 行受影响)
FNO a b c d e f g
---------------------------------- --------------------------------------- --------------------------------------- --------------------------------------- ----------- ----------------------- --------------------------------------- -----------
第1期 100000.00 20000.00 80000.00 5 2009-11-18 00:00:00.000 16000.00 11
第2期 100000.00 20000.00 80000.00 5 2009-12-18 00:00:00.000 16000.00 11
第3期 100000.00 20000.00 80000.00 5 2010-01-18 00:00:00.000 16000.00 11
第4期 100000.00 20000.00 80000.00 5 2010-02-18 00:00:00.000 16000.00 11
第5期 100000.00 20000.00 80000.00 5 2010-03-18 00:00:00.000 16000.00 11

(5 行受影响)


*/
sun485916 2009-11-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fredrickhu 的回复:]
SQL code----------------------------------------------------------------
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-11-18 11:25:54
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00?-
[/Quote]

sql2000中没 row_number()这个函数

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧