sql查询的结果集(row_number do dim dim dim dos)

发布于 2025-02-05 07:10:26 字数 421 浏览 4 评论 0原文

使用dbeaver一些自定义的Sybase驱动程序。 row_number不起作用:

不正确的语法附近“ over”

select row_number() over(), name
from table

也尝试了此

over (order by (select 1))
over (order by name)

尝试的变量:

SELECT语句分配值不得与数据回程操作结合使用,

declare @num int
set @num = 1
select name, @num = @num + 1
from table
cross join (select @num = 1)

然后使用主int键考虑临时表

using dbeaver some custom sybase driver.
row_number doesn't work:

incorrect syntax near 'over'

select row_number() over(), name
from table

tried also this

over (order by (select 1))
over (order by name)

tried variables:

select statement that assigns a value must not be combined with data-retrieval operations

declare @num int
set @num = 1
select name, @num = @num + 1
from table
cross join (select @num = 1)

Thinking about temporary table with primary int key

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

挽清梦 2025-02-12 07:10:26

如果名称列具有唯一名称,则可以使用子查询将行编号如下:

Select * from
(
    select (select count(*)+1 from table a where t.idName >a.idName ) row_number, name
    from table t  
)x order by row_number

If name column has unique names then you can use subquery to get your row numbered as below:

Select * from
(
    select (select count(*)+1 from table a where t.idName >a.idName ) row_number, name
    from table t  
)x order by row_number
瑶笙 2025-02-12 07:10:26

您可以创建一个带有身份(称为行号)的新临时表,该表将列举行为ID,然后返回该表。

SELECT rownumber=identity(10), name
  INTO #temp
  FROM table

SELECT * FROM #temp

您可以尝试将其变为身份的值,因为我不知道它的作用。

You can create a new temp table with Identity (call it row number) that will enumerate the rows as IDs and then return that table.

SELECT rownumber=identity(10), name
  INTO #temp
  FROM table

SELECT * FROM #temp

You can experiment with the value passed into Identity as I don't know what it does.

桃扇骨 2025-02-12 07:10:26

啊。旧问题再次...
首先,ASE并没有像智商那样支持窗口功能。 row_number()aver()..
但是您可以使用另一个ASE的功能获得类似的效果 - 身份(n)
这是一个简单的示例 -

1> create table #t1(str varchar(5))
2> go
1> insert #t1 values('haha')
2> insert #t1 values('hehe')
3> insert #t1 values('hoho')
4> go
1> select * from #t1
2> go
 str
 -----
 haha
 hehe
 hoho
1> select rownumber=identity(10),str into #t2 from #t1
2> go
(3 rows affected)
1> select * from #t2
2> go
 rownumber     str
 ------------- -----
             1 haha
             2 hehe
             3 hoho

(3 rows affected)

请注意 - 此函数 - 身份(n) - 只能在“ select in to to to”语句中使用,因此您需要使用它并将结果集放在temp表中,然后将其放在temp表中生成的隆起。
希望它有帮助。

ah. Old question again...
First, ASE didn't suppor the window function like IQ -- eg. this row_number() over ()..
But you can get the similar effect using another ASE's function -- identity(n)
Here's a simple Sample --

1> create table #t1(str varchar(5))
2> go
1> insert #t1 values('haha')
2> insert #t1 values('hehe')
3> insert #t1 values('hoho')
4> go
1> select * from #t1
2> go
 str
 -----
 haha
 hehe
 hoho
1> select rownumber=identity(10),str into #t2 from #t1
2> go
(3 rows affected)
1> select * from #t2
2> go
 rownumber     str
 ------------- -----
             1 haha
             2 hehe
             3 hoho

(3 rows affected)

Pls be noted -- this function -- identity(n) -- can only be used in "select into" statement, so you need to use it and put the resultset to a temp table then retrieve it with the generated rownumber.
Hope it help.

恋竹姑娘 2025-02-12 07:10:26
select COUNT(*) as number_row, name
from table

count()也是返回行号
尝试这个

select COUNT(*) as number_row, name
from table

COUNT() is also return number of row
Try This

优雅的叶子 2025-02-12 07:10:26
select ROW_NUMBER() OVER(ORDER BY name) as RowNum, name
from table

Over()在此指定一个列名和
<代码>作为用于设置列的名称和行列

尝试此

select ROW_NUMBER() OVER(ORDER BY name) as RowNum, name
from table

OVER() in that specify one column name and
AS is use to set name of column and row column

Try this

旧情勿念 2025-02-12 07:10:26

由临时表实现:
Alter表#tempt
添加ID数字(10,0)身份而不是null

realized by temporary table:
alter table #tempTable
add id numeric(10,0) identity not null

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文