Teradata:从表中删除n行

Teradata:从表中删除n行,teradata,sql-delete,Teradata,Sql Delete,我想从Teradata中的表中删除前n行或后n行。但我没有得到任何正确的质疑。有人能告诉我怎么做吗?我没有任何使用TeraData的经验,但如果我使用SQL,我会这样做: Delete From |TableName| where |the ID column Name| IN (Select top(n) |the ID column Name| from |TableName|) Delete From Customer where CustomerID IN (Select top(1

我想从Teradata中的表中删除前n行或后n行。但我没有得到任何正确的质疑。有人能告诉我怎么做吗?

我没有任何使用TeraData的经验,但如果我使用SQL,我会这样做:

Delete From |TableName| where |the ID column Name|
IN (Select top(n) |the ID column Name| from |TableName|)
Delete From Customer  where CustomerID
IN (Select top(10) CustomerID  from Customer)
例如,如果我有一个Customer表,这个表包含一个CustomerID作为主键列和CustomerName,我想删除前10行,我会这样:

Delete From |TableName| where |the ID column Name|
IN (Select top(n) |the ID column Name| from |TableName|)
Delete From Customer  where CustomerID
IN (Select top(10) CustomerID  from Customer)

我希望它能有所帮助

subselect中的Top N被限制在delete中,而不是在其他上下文中

因此,创建一个volatile表而不是subselect

create volatile table myDel as ( 
   select id from myTable
   sample .25
) with data on commit preserve rows;
delete T
from myTable T, myDel D
where T.id = D.id;
将删除25%的数据(顺便说一句,sample有很多选项如何构建sample)

使用volatile table和top n以及一些订单标准,您可以清楚地定义top/last是什么

create volatile table myDel as ( 
     select top 3 id from myTable order by col_1
) with data on commit preserve rows;

定义前n行。表中没有第一行或最后一行,它是一组无序的行:-)我的意思是说从开始或最后没有行。如何定义开始或最后?让我们举一个例子,我想从表中删除1/4条记录。我该怎么做?
从mytable中删除,其中random(1,4)=1
随机删除大约25%。但为什么要这样做呢?如果CustomerID上没有ORDER BY,TOP将返回最先完成的AMP中的行。这意味着每次执行查询时都会产生一个随机结果。如果在生产环境中盲目运行,这可能会产生不良后果。上面的查询不起作用,并且显示错误:子查询中不支持Top N