V
V
Virgil Merkel2020-02-06 23:59:55
SQL
Virgil Merkel, 2020-02-06 23:59:55

How to merge 2 sql queries into 1?

there are two subqueries in access, we need to combine them into one
qr_0 subquery:

SELECT Типы.[Код типа], Sum(Заказано.[Итого со скидкой]) AS [Sum-Итого со скидкой]
FROM (Типы INNER JOIN [Древесина (Чимал)] ON Типы.[Код типа] = [Древесина (Чимал)].[Код Типа]) INNER JOIN Заказано ON [Древесина (Чимал)].[Код Чимала] = Заказано.[Код Чимала]
GROUP BY Типы.[Код типа];

subquery qr_1:
SELECT Обходы.Название, Типы.[Код типа], Sum(Заказано.[Итого со скидкой]) AS [Sum-Итого со скидкой1], qr_0.[Sum-Итого со скидкой]
FROM ((Типы INNER JOIN (Обходы INNER JOIN [Древесина (Чимал)] ON Обходы.[Код обходщика] = [Древесина (Чимал)].[Код обходчика]) ON Типы.[Код типа] = [Древесина (Чимал)].[Код Типа]) INNER JOIN Заказано ON [Древесина (Чимал)].[Код Чимала] = Заказано.[Код Чимала]) INNER JOIN qr_0 ON Типы.[Код типа] = qr_0.[Код типа]
GROUP BY Обходы.Название, Типы.[Код типа], qr_0.[Sum-Итого со скидкой]
HAVING (((Обходы.Название)=[назв обх]));

"name bypass" - this is the input value, the name of the crawler
5e3c7ef3320ae361912260.png
thanks in advance :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Ryabov, 2020-02-13
@Vope

I can’t digest something, but judging by the fact that in both queries in GROUP BY you have a common field Types. [Type code] , you can do an inner join through it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question