You can't (unless you use dynamic SQL which unnecessary). You need to use a reporting tool. Re: 4. How do I convert rows to columns?
SQL projection should be known beforehand. Although this is listed in the links I have given earlier, still it is worth to specify one more time. PL/SQL 101 : Cursors and SQL Projection
If its is always 12 months back it is possible to write a generic query using the sql pivot clause.
if the numbers of columns is varying then your best bet is version 18s polymorphic table function. https://oracle-base.com/articles/18c/polymorphic-table-functions-18c
On a lower version you have to use dynmic sql. The question is alyways how you can deal with the output. It dependes on what you want to do with the result.
BTW: you wrote :" Here we are calculating each 12 rows sum.". In your Output you did no show a sum.
I need to convert row's into columns but year will be keep on changing, so that need to required dynamic query. Could you please help here.
Here we are calculating each 12 rows sum.
Col1 col2 2015 100 2016 120 2017 120 2018 110 2015 90 2016 80 2017 70 2018 20
Output:1st year(2015)2nd year(2016)3rd year(2017)4th Year(2018)
100 120 120 110 90 80 70 20