简体   繁体   English

将 Pivot 与子查询一起使用时,列定义不明确

[英]Column ambigously defined when using Pivot with subquery

I am trying to run this pivot query to show the dates as columns which are in this format: "MM/DD/YYYY" and the occurrences of some kind of ID's in each date:我正在尝试运行此数据透视查询以将日期显示为以下格式的列:“MM/DD/YYYY”以及每个日期中出现的某种 ID:

The column which contains the dates is "DATE_POSTED" -- DATA TYPE date The column which contains the ID's is "ID_INST" -- DATA TYPE varchar2包含日期的列是 "DATE_POSTED" -- DATA TYPE date 包含 ID 的列是 "ID_INST" -- DATA TYPE varchar2

Query:询问:

SELECT *
FROM (SELECT ID_INST, DATE_POSTED
      FROM total.table1) PIVOT XML (COUNT (DATE_POSTED)
                                           FOR (DATE_POSTED)
                                           IN  (SELECT distinct DATE_POSTED
                                                  FROM total.table1));

The error which i'm receiving is ORA-00918: column ambiguously defined, I did some searches but I keep getting this error.我收到的错误是 ORA-00918: 列定义不明确,我进行了一些搜索,但一直收到此错误。 Not sure if my approach is totally correct.不确定我的方法是否完全正确。 PS im using XML keyword due to the fact that it prompted: missing keyword PS 我使用 XML 关键字,因为它提示:缺少关键字

Current table:当前表: 当前表

Expected result:预期结果: 预期结果

Try the following:请尝试以下操作:

SELECT *
  FROM (SELECT ID_INST, TO_CHAR(DATE_POSTED, 'DD-Mon')  DATE_POSTED
          FROM TOTAL.TABLE1)
  PIVOT XML (COUNT(DATE_POSTED)
             FOR DATE_POSTED IN (ANY))

The poblem might be caused by the fact, that date also stores time information additional to the date.问题可能是由事实引起的,该日期还存储了除日期之外的时间信息。

So you get different values for DATE_POSTED , but the conversion to char leads to the same column name as the date format mask cuts the time information.因此,您会获得不同的DATE_POSTED值,但转换为 char 会导致相同的列名,因为日期格式掩码会削减时间信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM