Ответить на сообщение
Вернуться к теме
Вы отвечаете на сообщение:
ник: Lukas Вот специально еще одного монстра соорудил, для проверки. Раскидал счета по столбикам для наглядности + итоги. И в итоге: имеем тот-же результат, что и в предыдущих двух запросах:
SELECT u.Acc As Счет, Sum(a1011) As [1011(1)], Sum(a2021) As [2021(1)], Sum(a5051) As [5051(2)], Sum(a6061) As [6061(2)], Sum(a10112) As [1011(2)], Sum(a20212) As [2021(2)], Sum(a1011) + Sum(a5051) - Sum(a6061) - Sum(a10112) As [1011(1)+5060(2)-6061(2)-1011(2)], Sum(a2021) - Sum(a5051) + Sum(a6061) - Sum(a20212) As [2021(1)-5060(2)+6061(2)-2021(2)], Sum(a1011) + Sum(a5051) - Sum(a6061) - Sum(a10112) + Sum(a2021) - Sum(a5051) + Sum(a6061) - Sum(a20212) As [Итог10+Итог20] FROM ( SELECT Mid(t1.Account,3) As Acc, t1.Amount As a1011, 0 As a2021, 0 As a5051, 0 As a6061, 0 As a10112, 0 As a20212 FROM New1txt t1 WHERE Left(t1.Account,2) In ('10','11') UNION ALL SELECT Mid(t1.Account,3) As Acc, 0 As a1011, t1.Amount As a2021, 0 As a5051, 0 As a6061, 0 As a10112, 0 As a20212 FROM New1txt t1 WHERE Left(t1.Account,2) In ('20','21') UNION ALL SELECT Mid(t2.Account,3) As Acc, 0 As a1011, 0 As a2021, t2.Amount As a5051, 0 As a6061, 0 As a10112, 0 As a20212 FROM New2txt t2 WHERE Left(t2.Account,2) In ('50','51') UNION ALL SELECT Mid(t2.Account,3) As Acc, 0 As a1011, 0 As a2021, 0 As a5051, t2.Amount As a6061, 0 As a10112, 0 As a20212 FROM New2txt t2 WHERE Left(t2.Account,2) In ('60','61') UNION ALL SELECT Mid(t2.Account,3) As Acc, 0 As a1011, 0 As a2021, 0 As a5051, 0 As a6061, t2.Amount As a10112, 0 As a20212 FROM New2txt t2 WHERE Left(t2.Account,2) In ('10','11') UNION ALL SELECT Mid(t2.Account,3) As Acc, 0 As a1011, 0 As a2021, 0 As a5051, 0 As a6061, 0 As a10112, t2.Amount As a20212 FROM New2txt t2 WHERE Left(t2.Account,2) In ('20','21') ) u GROUP BY u.Acc ORDER BY u.Acc;
Ваше имя:
Пароль:
Сообщение:
Прикрепить:
Для вставки смайлов в текст щелкните по значку.