目前的问题是如何在select中取到列名

解决方案 »

  1.   

    select year as 日期,month01 as 销售数量 from 表 where year='200601'
    union
    select year as 日期,month02 as 销售数量 from 表 where year='200602'
    union
    select year as 日期,month03 as 销售数量 from 表 where year='200603'
    union
    .....
    union
    select year as 日期,month12 as 销售数量 from 表 where year='200612'
      

  2.   

    select year as 日期
    month01  as 销售数量
    from 表
    union 
    select year as 日期
    month02  as 销售数量
    from 表
    .
    .
    .
    .
      

  3.   

    修正一下:
    select year||'-01' as 日期,month01 as 销售数量 from 表 where year='2006'
    union
    select year||'-02' as 日期,month02 as 销售数量 from 表 where year='2006'
    union
    select year||'-03' as 日期,month03 as 销售数量 from 表 where year='2006'
    union
    .....
    union
    select year||'-12' as 日期,month12 as 销售数量 from 表 where year='2006'
      

  4.   

    不是要并操作,我只想每月根据SYSDATE的时间取出对应的列。
      

  5.   

    where 条件修改一下:
    where year=to_char(sysdate,'yyyy')
      

  6.   

    回yjdn(文刀无尽)
    我在sql server中建了个DTS包,用代理每月从ORACLE数据库取出当月销量。
    语句要求以原表列名monthXX后两位数字=datepart(month,getdate())为条件
      

  7.   

    你是说现在是200607月,只取出2006年‘month07’ 字段对应的销量?
      

  8.   

    再修正一下:
    select aa.日期,aa.销售数量 
    from
    (
    select year||'01' as 日期,month01 as 销售数量 from 表 where year='2006'
    union
    select year||'02' as 日期,month02 as 销售数量 from 表 where year=to_char(sysdate,'yyyy')
    union
    select year||'03' as 日期,month03 as 销售数量 from 表 where year=to_char(sysdate,'yyyy')
    union
    .....
    union
    select year||'12' as 日期,month12 as 销售数量 from 表 where year=to_char(sysdate,'yyyy')
    ) aa
    where aa.日期=to_char(sysdate,'yyyymm')
      

  9.   

    回yjdn(文刀无尽)
    我在sql server中建了个DTS包,用代理每月从ORACLE数据库取出当月销量。
    语句要求以原表列名monthXX后两位数字=datepart(month,getdate())为条件--这好像也和你的行列变换没有什么关系吧,
    你不是固定有12个月吗?
    而且这些字段都是固定的吧?
    还有必要考虑上面的东东吗?
      

  10.   

    select year || '-01' as 日期
    month01  as 销售数量
    from 表
    union 
    select year || '-02' as 日期
    month02  as 销售数量
    from 表 where 
    .
    .
    .
    .--这样不就OK?