O
O
Oleg Seledets2018-12-16 01:17:25
MySQL
Oleg Seledets, 2018-12-16 01:17:25

How to correctly complete a SQL query?

Hello, tell me how to correctly supplement this query so that between the columns years and summa2 there is a column percent, which will contain the percentage by how much the value of summa has changed relative to summa2 as a percentage?

SELECT reservtable.sudovlad, reservtable.summa, reservtable.years, reservtable2.summa2, reservtable2.years2
FROM(
  SELECT sudovlad, Sum(gruz_pass) AS summa, Extract(YEAR from data_vih_p_ot ) AS years 
  FROM ships WHERE sudovlad = 'pere' 
  GROUP by Extract(YEAR from data_vih_p_ot )
    ) reservtable,
    (SELECT sudovlad, Sum(gruz_pass) AS summa2, Extract(YEAR from data_vih_p_ot ) AS years2 
  FROM ships WHERE sudovlad = 'pere' 
  GROUP by Extract(YEAR from data_vih_p_ot )
    ) reservtable2
WHERE reservtable.years=2018 AND reservtable2.years2=2017

5c157d6831166257011222.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
morricone85, 2018-12-16
@morricone85

I, in general, am on the side of the base, I would not carry out such calculations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question