SQL> select * from a;         A          B
---------- ----------
         1          2
         2          3
         5          6
         7          8
SQL> create view ViewA
  2  as select sum(a) a,sum(b) b from A;视图已建立。SQL> select * from viewa;         A          B
---------- ----------
        15         19SQL> select a from viewa;         A
----------
        15

解决方案 »

  1.   

    新的问题是这样的:
    已建立ViewA:字段为date(字符格式yyyy-mm),a,b (相当于月表)
    要建立VIewB:select to_char(to_date(date,'yyyy-mm'),'yyyy')  date, sum(a) a,sum(b) b from ViewA  group  by to_char(to_date(dtime,'yyyy-mm'),'yyyy')(相当于年表)
    显示to_char(to_date(dtime,'yyyy-mm'),'yyyy')为“无效的列名”
      

  2.   

    select to_char(to_date(date,'yyyy-mm'),'yyyy')  date, sum(a) a,sum(b) b from ViewA  group  by date你SELECT后面用了别名,在后面引用时就要用别名
      

  3.   

    select to_char(to_date(date,'yyyy-mm'),'yyyy')  date, sum(a) a,sum(b) b from ViewA  group  by to_char(to_date(date,'yyyy-mm'),'yyyy')
      

  4.   

    to_char(to_date(dtime,'yyyy-mm'),'yyyy')
    -----------------------------------------
        错语的写法!!!改为: to_char(dtime,'yyyy') 就可以了.