M
M
marselabdullin2020-11-18 17:02:52
Oracle
marselabdullin, 2020-11-18 17:02:52

How to write nested query in select?

There is a need for this query:

select (select sum(rashody) from transport_reestr where transport_type=‘taxi’)/ sum(rashody) from transport_reestr

Gives an error not single group group function, although grouping is not needed here and the sum goes over all columns

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2020-11-18
@idShura

Need to add GROUP BY

SELECT (SELECT SUM (RASHODY)
          FROM TRANSPORT_REESTR
         WHERE TRANSPORT_TYPE = 'TAXI') / SUM (RASHODY)
  FROM TRANSPORT_REESTR
  GROUP BY НАЗВАНИЕ_ПОЛЯ;

Apparently you were trying to portray this?
SELECT (SELECT SUM (RASHODY)
            FROM TRANSPORT_REESTR
           WHERE TRANSPORT_TYPE = 'TAXI') / 
         (SELECT SUM (RASHODY) 
            FROM TRANSPORT_REESTR)
    FROM DUAL;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question