表A如下
a, b
12, 34
12, 56
12, 23
13, 33
14, 11
14, 15
如保用一条语句得到
a, b c
12, 23 1
12, 34 2
12, 56 3
13, 33 1
14, 11 1
14, 15 2
谢谢
a, b
12, 34
12, 56
12, 23
13, 33
14, 11
14, 15
如保用一条语句得到
a, b c
12, 23 1
12, 34 2
12, 56 3
13, 33 1
14, 11 1
14, 15 2
谢谢
解决方案 »
- sql语句循环嵌套
- not in 用法
- 求助: 关于sum聚合函数的使用问题
- 统计代码算法查错,只要是在一年的最后一周统计就出错,其他任何时间段都没问题
- 关于日志,如何删除大数据量的记录。高手赐教
- 小f ,PRIMARY KEY (栏目流水号) identity(int,1,1)
- isnull(max(num),0)在Select语句里什么意识?
- 存储过程中的事务回滚出错,提示找不到该名称的事务
- 有点难度的update语句
- 小妹请教各位GGJJ一个把数据导成脚本的问题
- 数据源(ODBC)打开时为繁体,且窗口大小固定,找到odbcad32.exe时,也如此,从别机上copy一个过来依旧如此,why?请各位指点,谢谢!
- 高分急盼:如何截取字符串?
insert into @t select 12, 34
union all select 12, 56
union all select 12, 23
union all select 13, 33
union all select 14, 11
union all select 14, 15select *,c=(select count(*)+1 from @t where a=a.a and b<a.b) from @t a order by a,b
declare @a table (a int, b int)
insert into @a
select 12,34 union all
select 12,56 union all
select 12,23 union all
select 13,33 union all
select 14,11 union all
select 14,15select * from @aselect
a,
b,
(select count(*)+1 from @a where a=a.a and b<a.b) c
from @a a
order by a,bset nocount off/*
a b
----------- -----------
12 34
12 56
12 23
13 33
14 11
14 15a b c
----------- ----------- -----------
12 23 1
12 34 2
12 56 3
13 33 1
14 11 1
14 15 2
*/
(select count(*)+1 from @a where a=a.a and b<a.b) c
改成
(select count(*) from @a where a=a.a and b<=a.b) c
也一样
服务器: 消息 156,级别 15,状态 1,行 1
Incorrect syntax near the keyword 'table'.
服务器: 消息 170,级别 15,状态 1,行 10
Line 10: Incorrect syntax near '@a'.
insert into tb select 12, 34
union all select 12, 56
union all select 12, 23
union all select 13, 33
union all select 14, 11
union all select 14, 15select *,c=(select count(*)+1 from tb where a=a.a and b<a.b) from tb a order by a,bdrop table tb