Answer the question
In order to leave comments, you need to log in
How to combine horizontally the results of two queries?
A meaningless, but simple pseudo-language example
SELECT contract AS ct, contractDate, subscriber, (SELECT cost FROM upload WHERE contract = ct)
FROM upload
That is, I want to somehow pass the value of the contract inside to use it in the condition there. Is it possible to do this?
PS The client can have international and long-distance calls, it is necessary that the request displays the cost of both in one line. If you use normal grouping, the output will be two lines. And my question assumes something like UNION, but only horizontally.
Answer the question
In order to leave comments, you need to log in
LEFT JOIN - to include fields from other tables
GROUP BY to join rows on selected fields
SELECT contract , contractDate, subscriber, SUM( cost ) AS 'cost'
FROM upload
GROUP BY contract , contractDate, subscriber
Select ct,
contractDate,
subscriber,
'Междугордние',
[Междугордние],
'Международные',
[Международные]
from (SELECT [contract] AS ct, contractDate, subscriber,[тип_звонка],cost from upload ) t
pivot (sum([cost]) for [тип_звонка] in ([Междугордние],[Международные])) pvt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question