Тема: Псевдонім стовпців в PostgreSQL
Добрий день! В мене виникло питання, чи можна зробити так, щоб в назві стовпця замість 2007 записати, щось типу
(select extract (year from current_date))-10
, тобто якщо сьогодні 2017 рік то стовбець мав назву 2007, а якщо 2018 - 2008?
select sum(case when year_work = ((select extract (year from current_date))-10) then 1 else 0 end) as "2007",
sum(case when year_work = ((select extract (year from current_date))-9) then 1 else 0 end) as "2008",
sum(case when year_work = ((select extract (year from current_date))-8) then 1 else 0 end) as "2009",
sum(case when year_work = ((select extract (year from current_date))-7) then 1 else 0 end) as "2010",
sum(case when year_work = ((select extract (year from current_date))-6) then 1 else 0 end) as "2011",
sum(case when year_work = ((select extract (year from current_date))-5) then 1 else 0 end) as "2012",
sum(case when year_work = ((select extract (year from current_date))-4) then 1 else 0 end) as "2013",
sum(case when year_work = ((select extract (year from current_date))-3) then 1 else 0 end) as "2014",
sum(case when year_work = ((select extract (year from current_date))-2) then 1 else 0 end) as "2015",
sum(case when year_work = ((select extract (year from current_date))-1) then 1 else 0 end) as "2016",
sum(case when year_work = (select extract (year from current_date)) then 1 else 0 end) as "2017"
from rodovische;