【问题标题】:Add columns to select *添加列以选择 *
【发布时间】:2011-12-21 02:10:56
【问题描述】:

在 SQL Server 中,我曾经做过这样的事情来为选择添加额外的列:

select *,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end as end_date_modified
from WEIGHTED_AVERAGE w1

但 Oracle 中的以下情况导致“ORA-00923 FROM 关键字未在预期的位置找到”:

select *,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end end_date_modified
from WEIGHTED_AVERAGE w1

我已经搜索了所有内容,但无法弄清楚如何在 Oracle 中实现这一点。

【问题讨论】:

  • 也考虑一下,不要使用 *,这可能需要更多的时间,但可以帮助您在以后列更改时为您提供更好的错误消息,或者随着表的增长减少传输的数据量.

标签: sql sql-server oracle


【解决方案1】:

试试这个

select w1.*,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end end_date_modified
from WEIGHTED_AVERAGE w1

【讨论】:

  • @vitorfs - 正是我想要的,谢谢。有你的第一个接受的答案:-)
【解决方案2】:

将 SELECT 的开头修改为 w1.*

【讨论】:

    猜你喜欢
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    相关资源
    最近更新 更多