Teradata使用Top 10和Distinct

时间:2016-11-23 18:08:20

标签: sql teradata

我收到一条错误消息,说我不能使用Top 10,我想知道是否有任何方法可以让我的查询以这种方式工作。这就是错误所说的。

[Teradata Database] [6916] TOP N语法错误:DISTINCT选项不支持前N个选项。

以下查询: 谢谢。

 Select Distinct TOP 10   t1.Adjustment_ID, t1.OfficeNum, t1.InvoiceNum, t1.PatientNum,
t1.CurrentStatus, t1.AdjustmentTotal, t1.SubmittedOn, t1.UserSubmitted,
t1.Invoice_Type, t1.Pat_First_Name, t1.Pat_Last_Name,t2.Reason_Code FROM App_UnityAdj_AdjInfo_Tbl t1
Left Join RCM_WORK_PRD.App_UnityAdj_AdjRecord_Tbl t2 
On t1.Adjustment_ID = t2.Adjustment_ID
Where t1.UserSubmitted = 'Name' AND (t1.CurrentStatus = 'Pending' OR t1.CurrentStatus = 'Deny')

2 个答案:

答案 0 :(得分:2)

你想做什么?您SELECT中的列不在GROUP BY中。您还有TOP没有ORDER BY,这是可疑的。

一种简单的方法是将所有SELECT列移至GROUP BY

select TOP 10  t1.Adjustment_ID, t1.OfficeNum, t1.InvoiceNum, t1.PatientNum,
       t1.CurrentStatus, t1.AdjustmentTotal, t1.SubmittedOn, t1.UserSubmitted,
       t1.Invoice_Type, t1.Pat_First_Name, t1.Pat_Last_Name, t2.Reason_Code
from App_UnityAdj_AdjInfo_Tbl t1 Left Join  
     RCM_WORK_PRD.App_UnityAdj_AdjRecord_Tbl t2 
     On t1.Adjustment_ID = t2.Adjustment_ID
where t1.UserSubmitted = 'Name' AND
      t1.CurrentStatus in ('Pending', 'Deny')
group by t1.Adjustment_ID, t1.OfficeNum, t1.InvoiceNum, t1.PatientNum,
         t1.CurrentStatus, t1.AdjustmentTotal, t1.SubmittedOn, t1.UserSubmitted,
         t1.Invoice_Type, t1.Pat_First_Name, t1.Pat_Last_Name,t2.Reason_Code;

答案 1 :(得分:1)

我想我想出来了,万一有人想知道它是样本10

Select Distinct t1.Adjustment_ID, t1.OfficeNum, t1.InvoiceNum, t1.PatientNum,
t1.CurrentStatus, t1.AdjustmentTotal, t1.SubmittedOn, t1.UserSubmitted,
t1.Invoice_Type, t1.Pat_First_Name, t1.Pat_Last_Name,t2.Reason_Code FROM    App_UnityAdj_AdjInfo_Tbl t1
Left Join RCM_WORK_PRD.App_UnityAdj_AdjRecord_Tbl t2 
On t1.Adjustment_ID = t2.Adjustment_ID
Where t1.AssignedTo IS null AND (t1.CurrentStatus = 'Pending')
sample 10