有人知道此查询出了什么问题吗?

 SELECT DISTINCT c.CN as ClaimNumber,
         a.ItemDate as BillReceivedDate, c.DTN as
 DocTrackNumber
         FROM ItemData a,
         ItemDataPage b,
         KeyGroupData c
         WHERE a.ItemTypeNum in (112, 113, 116, 172, 189)
         AND a.ItemNum = b.ItemNum
         AND b.ItemNum = c.ItemNum
         ORDER BY a.DateStored DESC;


我已经完成了T-Sql的大部分职业,这对我来说似乎是正确的,但是此查询是针对Oracle数据库的,Toad只是将光标放在Order By部分中的a.DateStored上。我确信这对任何执行PL / SQL的人都是基本的。

谢谢!

[编辑]为了将来参考,SQL * Plus给出的错误是:“ ORA-01791:不是SELECTED表达式”

最佳答案

您将需要修改查询,如下所示:

SELECT DISTINCT c.CN as ClaimNumber,
         a.ItemDate as BillReceivedDate, c.DTN as
 DocTrackNumber, a.DateStored
         FROM ItemData a,
         ItemDataPage b,
         KeyGroupData c
         WHERE a.ItemTypeNum in (112, 113, 116, 172, 189)
         AND a.ItemNum = b.ItemNum
         AND b.ItemNum = c.ItemNum
         ORDER BY a.DateStored DESC;


进行DISTINCT时,您的订单依据必须是所选列之一。

08-03 15:32