我想问一下刚才这个帖子
http://topic.csdn.net/u/20080123/12/53988160-2bfa-4de3-affa-ac9f73578d5e.htmlwhere cnt < n.cnt
这里判断的条件,其中cnt代表的字段一定要用数字么?用汉字的话可以么?比如:where 省份名称 < n.省份名称
这样查出来的结果,px整个一列都为1了,可是sql集查询出来没有数字列,该怎么办呢?
http://topic.csdn.net/u/20080123/12/53988160-2bfa-4de3-affa-ac9f73578d5e.htmlwhere cnt < n.cnt
这里判断的条件,其中cnt代表的字段一定要用数字么?用汉字的话可以么?比如:where 省份名称 < n.省份名称
这样查出来的结果,px整个一列都为1了,可是sql集查询出来没有数字列,该怎么办呢?
select * from tmp
with t(col)
as
(select 1
union all
select col+1 from t where col+1<100)----2000只有用记录数、必须有一列是有大小关系、没有时用唯一列判断生成的递增不一值。。通常用临时表
insert into @tb select '河北'
insert into @tb select '河南'
insert into @tb select '河西'
insert into @tb select '河东'
select id=row_number() over (order by v),v from @tbid v
1 河北
2 河东
3 河南
4 河西
insert into @tb select '河北'
insert into @tb select '河南'
insert into @tb select '河西'
insert into @tb select '河东'
select Pid = (select count(1) + 1 from @tb where v <a.v),*
from @tb a
order by pId/*Pid v
----------- --------------------------------------------------------------------------------
1 河北
2 河东
3 河南
4 河西(所影响的行数为 4 行)
*/
select 序列 = (select count(1) from
(
SELECT t.RES_DESCR 省份名称
FROM v_res_netdevice_desc t ,res_def_class d
) m where 省份名称 < n.省份名称) + 1,* from
(
SELECT t.RES_DESCR 省份名称
FROM v_res_netdevice_desc t ,res_def_class d
) n
换
省份名称 = n.省份名称 and id<n.id找个标识字段替换了id
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) m where id < n.id) + 1,* from
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) n
这么写的话,说列名id无效,该怎么写呢?
insert into @tb select '河北'
insert into @tb select '河南'
insert into @tb select '河西'
insert into @tb select '河东'
select Pid = (select count(1) + 1 from (select * from @tb) b where v <a.v),*
from (select * from @tb) a
order by pId/*Pid v
----------- --------------------------------------------------------------------------------
1 河北
2 河东
3 河南
4 河西(所影响的行数为 4 行)
*/
要不就写存储过程用临时表,这样写不行
(select count(1) from tab
where a<x.a or a=x.a and b<x.b or a=x.a and b=x.b and c<x.c or a=x.a and b=x.b and c=x.c and d<=x.d
) as 序号
from tab x
order by a,b,c,d
无枪狙击手
等 级:
发表于:2008-01-23 14:45:2318楼 得分:0
ID在你的列表中没有呀
--------------
是没有呀,没有的话,这里的where条件要怎么写呢?多谢帮忙啊!
select *,
IDENTITY(int,1,1) as 序号
into #t
from tab
order by a,b --注意a,b可能不唯一select * from #tdrop table #t
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) m where 地理位置 < n.地理位置) + 1,*
from
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) n你这里面没有 “省份名称”
where 省份名称 < n.省份名称 or (省份名称 < n.省份名称 and cnt < n.cnt)
where 省份名称 < n.省份名称 or (省份名称 = n.省份名称 and cnt < n.cnt)
潇洒老乌龟(原名:爱新觉罗.毓华)
等 级:
发表于:2008-01-23 14:55:5226楼 得分:0
SQL code--错了.加个条件:
where 省份名称 < n.省份名称 or (省份名称 = n.省份名称 and cnt < n.cnt)
-----------------
现在没有 cnt 这个字段了,改怎么写呢?
无枪狙击手
等 级:
发表于:2008-01-23 14:55:0324楼 得分:0
SQL codeselect 序列 = (select count(1) from
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) m where 地理位置 < n.地理位置) + 1,*
from
(
SELECT t.RES_DESCR 设备名称,t.model as 设备型号,d.class_descr as 设备类型,t.vendor as 生产厂商, t.integrator as 集成商,t.supplier as 供应商,
t.appsystem as 业务系统, t.location 地理位置
FROM v_res_netdevice_desc t ,res_def_class d
) n
你这里面没有 “省份名称”
--------------
哦,错了,是设备名称
只要能通过某个(或某多个字段的组合)能区分大小即可.如果没有,则只能插入临时表(或使用sql 2005 row_number).具体方法(某个的我不写了,如cnt < n.cnt)
多个的:con1 < n.con1 or (con1 = n.con1 and con2 < n.con2) or (con1 = n.con1 and con2 = n.con2 and con3 < n.con3)
insert into @tb select '河北'
insert into @tb select '河南'
insert into @tb select '河西'
insert into @tb select '河东'
select Pid = (select count(1) + 1 from (select * from @tb) b where v <a.v),*
from (select * from @tb) a
order by pId/*Pid v
----------- --------------------------------------------------------------------------------
1 河北
2 河东
3 河南
4 河西(所影响的行数为 4 行)
*/
------------------
这段代码是什么意思啊?这个不是按汉字的字段排出来了么?