选择表格中除第一行以外的行

16

我想选择除顶部行外的所有行,有人可以帮我解决这个查询吗。


1
“Top one” 是如何定义的 - 实际上是哪个查询? - Will A
4个回答

10
with cte as
(
    select *, row_number() over (order by CustomerId) RowNumber
    from Sales.Customer
)
select *
from cte
where RowNumber != 1

或者

select *
from
(
    select *, row_number() over (order by CustomerId) RowNumber
    from Sales.Customer
) tt
where RowNumber != 1

使用CTE表达式: ( 选择,row_number() over (order by loan_issue_id) RowNumber 从dbo.loan_issue_mcg中 ) 选择 从cte中 其中RowNumber!=1且loan_id = 1170 **这个仍然显示所有行 - Dinup Kandel
@Dinup Kandel - 在 cte 内部添加 where loan_id=1170 - Alex Aza
@Dinup kandel - 使用cte作为(选择*,row_number() over (order by loan_issue_id) RowNumber from dbo.loan_issue_mcg where loan_id=1170)的别名,选择从cte中RowNumber不等于1的所有内容。 - Alex Aza

7
在SQL Server 2012中,您可以这样做:
select * from TableName order by Id offset 1 rows

1
SELECT * FROM table1
EXCEPT SELECT TOP 1 * FROM table1

0
如果已知id属性,那么我们可以使用...
SELECT t1.* FROM table t1 LEFT JOIN (
  SELECT id
  FROM table 
  LIMIT 1
) t2 ON t1.id = t2.id
WHERE t2.id IS NULL;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接