select row_number() over (order by amount desc) newOrder ,t.* from Tab t
通过如上语句可以得到排序后的行号
但是如果把行号更新到对应行的字段NewOrder中呢?
求助。
7 个解决方案
#1
--如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
-----------------------
问题已解决,但是结贴需要人来回复个啊
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
-----------------------
问题已解决,但是结贴需要人来回复个啊
#2
连个要分的人也没么?
#3
如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
#4
#5
#6
如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
#7
#1
--如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
-----------------------
问题已解决,但是结贴需要人来回复个啊
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
-----------------------
问题已解决,但是结贴需要人来回复个啊
#2
连个要分的人也没么?
#3
如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
#4
#5
#6
如果表有主键,可以使用主键关联,如果没有,可以使用rowid来关联更新
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);
UPDATE Tab a
SET a.neworder =
(SELECT *
FROM (SELECT row_number() over(ORDER BY amount DESC) newOrder,
ROWID browid
FROM Tab t) b
WHERE b.browid = a.rowid);