select * from APTEST
结果如下:
--------------------------------------------------------------------
BranchCD LineCD GroupCD ProductCD QtyCount MoneyCount
32 1 1 1001 100.0000 100.0000
32 1 1 1002 100.0000 100.0000
32 1 2 1003 100.0000 100.0000
32 1 2 1004 100.0000 100.0000
32 2 1 1005 100.0000 100.0000
32 2 1 1006 100.0000 100.0000
64 1 1 1007 100.0000 100.0000
--------------------------------------------------------------------
想要这种结果,在查询的时候添加一个序号列,我的操作:
SELECT
identity(int , 1,1) AS N
,*
INTO #A
FROM APTEST
SELECT * FROM #A
想问下如果不用临时表能不能实现呢
----------------------------------------------------------------------------------
N BranchCD LineCD GroupCD ProductCD QtyCount MoneyCount
1 32 1 1 1001 100.0000 100.0000
2 32 1 1 1002 100.0000 100.0000
3 32 1 2 1003 100.0000 100.0000
4 32 1 2 1004 100.0000 100.0000
5 32 2 1 1005 100.0000 100.0000
6 32 2 1 1006 100.0000 100.0000
7 64 1 1 1007 100.0000 100.0000
结果如下:
--------------------------------------------------------------------
BranchCD LineCD GroupCD ProductCD QtyCount MoneyCount
32 1 1 1001 100.0000 100.0000
32 1 1 1002 100.0000 100.0000
32 1 2 1003 100.0000 100.0000
32 1 2 1004 100.0000 100.0000
32 2 1 1005 100.0000 100.0000
32 2 1 1006 100.0000 100.0000
64 1 1 1007 100.0000 100.0000
--------------------------------------------------------------------
想要这种结果,在查询的时候添加一个序号列,我的操作:
SELECT
identity(int , 1,1) AS N
,*
INTO #A
FROM APTEST
SELECT * FROM #A
想问下如果不用临时表能不能实现呢
----------------------------------------------------------------------------------
N BranchCD LineCD GroupCD ProductCD QtyCount MoneyCount
1 32 1 1 1001 100.0000 100.0000
2 32 1 1 1002 100.0000 100.0000
3 32 1 2 1003 100.0000 100.0000
4 32 1 2 1004 100.0000 100.0000
5 32 2 1 1005 100.0000 100.0000
6 32 2 1 1006 100.0000 100.0000
7 64 1 1 1007 100.0000 100.0000
解决方案 »
- WPF用什么开发工具
- decimal.ToString("#0.00")与decimal.ToString("#.##")的区别
- 构造函数的继承问题?
- ~~~~千古疑难 HttpWebRequest 获取中文网页乱码
- .net 中数据库操作很耗时吗?
- 在数据库中设定了用户名时 登录为什么不行 帮忙看一下
- 新手 现在公司是做moss 想问一个大型的高并发的系统moss是不是做不了呢?
- 调用API,调用DLL,内嵌ASM代码在C#中好像特别麻烦?
- C#怎末把unicode码转换成字符?
- c# 小程序获取手机验证码后台服务器代码
- winform 特效问题
- VS2005 c# web 中用什么控件 来 显示GIF图片,我用 Image控件 显示 的GIF图片不会动?
declare @T table ([BranchCD] int,[LineCD] int,[GroupCD] int,[ProductCD] int,[QtyCount] numeric(7,4),[MoneyCount] numeric(7,4))
insert into @T
select 32,1,1,1001,100.0000,100.0000 union all
select 32,1,1,1002,100.0000,100.0000 union all
select 32,1,2,1003,100.0000,100.0000 union all
select 32,1,2,1004,100.0000,100.0000 union all
select 32,2,1,1005,100.0000,100.0000 union all
select 32,2,1,1006,100.0000,100.0000 union all
select 64,1,1,1007,100.0000,100.0000--select * from @T
--Code
--SQL2000
select N=(select count(*)+1 from @T where [ProductCD]<a.[ProductCD]),
* from @T a--SQL2005
select N=ROW_NUMBER() over(order by [ProductCD]),
* from @T a--Result
/*
N BranchCD LineCD GroupCD ProductCD QtyCount MoneyCount
----------- ----------- ----------- ----------- ----------- --------------------------------------- ---------------------------------------
1 32 1 1 1001 100.0000 100.0000
2 32 1 1 1002 100.0000 100.0000
3 32 1 2 1003 100.0000 100.0000
4 32 1 2 1004 100.0000 100.0000
5 32 2 1 1005 100.0000 100.0000
6 32 2 1 1006 100.0000 100.0000
7 64 1 1 1007 100.0000 100.0000
*/