此视图返回表,其中包含今年的数据,
| cat_name | This year |
| cat1 | 12 |
| cat2 | 3 |
CREATE OR REPLACE VIEW view_users_by_category_on_years AS SELECT subquery.cat_name, sum(subquery."This year") AS "This year" FROM ( SELECT DISTINCT view_users_by_category_on_years.cat_name, CASE WHEN view_users_by_category_on_years."YEAR" = date_part('year'::text, now()) THEN view_users_by_category_on_years.summ ELSE NULL::double precision END AS "Текущий год" FROM view_users_by_category_on_years GROUP BY view_users_by_category_on_years.cat_name, view_users_by_category_on_years."YEAR", view_users_by_category_on_years.summ) subquery GROUP BY subquery.cat_name;
但我不知道如何重新命名专栏#34;今年"动态改变"今年"到2015年或1992年,视情况而定。
也许有人这样做或者知道怎么样?