Answer the question
In order to leave comments, you need to log in
How to make such request in the temporary table?
As from such a table
It seems like I understand that you need to combine by name and year. but in calculating the amount and the difference between the current and the previous year, problems arise.
--------------------------------------
UPD1
did so far like this:
SELECT sudovlad, summa, years, (Sum(summa*100)/summa2) AS percent, summa2, years2 FROM (SELECT sudovlad, Sum(gruz_pass) AS summa, year(data_vih_p_ot) AS years, (Sum(gruz_pass)*100)/Sum(gruz_pass) AS percent, year(data_vih_p_ot) AS years2, Sum(gruz_pass) AS summa2 FROM pool_management.ships WHERE sudovlad = 'pere' GROUP by year(data_vih_p_ot) ) reservtable
WHERE years=2018
Answer the question
In order to leave comments, you need to log in
This process is called transposition (see here ). It is done either by PIVOT/UNPIVOT expressions or by constructing a query like
select group_concat(if(v='a', c, null)) a,
group_concat(if(v='b', c, null)) b,
group_concat(if(v='c', c, null)) c
from (select value v, Count(value) c
from t1
group by value ) temp
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question