SELECT
'2016 - 17' as 'Years',
SUM("svalue") as 'Value',
'Sale' as 'Type',
"code" as 'FACode',
'Apr 1 - Jan 31' as 'Period'
FROM "FCJOIN"
WHERE "code" IN
(
SELECT "fccode"
FROM "fcdetails"
)
AND (("year" = '2016' AND "month" >= '04')
OR ("year" = '2017' AND "month" <= '01'))
GROUP BY "code"
UNION ALL
SELECT
'2017 - 18' as 'Years',
SUM("svalue") as 'Value',
'Sale' as 'Type',
"code" as 'FACode',
'Apr 1 - Jan 31' as 'Period'
FROM "FCJOIN"
WHERE "code" IN
(
SELECT "fccode"
FROM "fcdetails"
)
AND (("year" = '2017' AND "month" >= '04')
OR ("year" = '2018' AND "month" <= '01'))
GROUP BY "code"
UNION ALL
SELECT
'2018 - 19' as 'Years',
SUM("svalue") as 'Value',
'Sale' as 'Type',
"code" as 'FACode',
'Apr 1 - Jan 31' as 'Period'
FROM "FCJOIN"
WHERE "code" IN
(
SELECT "fccode"
FROM "fcdetails"
)
AND (("year" = '2018' AND "month" >= '04')
OR ("year" = '2019' AND "month" <= '01'))
GROUP BY "code"
UNION ALL
SELECT
'2019 - 20' as 'Years',
SUM("svalue") as 'Value',
'Sale' as 'Type',
"code" as 'FACode',
'Apr 1 - Jan 31' as 'Period'
FROM "FCJOIN"
WHERE "code" IN
(
SELECT "fccode"
FROM "fcdetails"
)
AND (("year" = '2019' AND "month" >= '04')
OR ("year" = '2020' AND "month" <= '01'))
GROUP BY "code"
Из приведенного выше запроса я получаю SUM (svalue) за период
April 2016 - Jan 2017
April 2017 - Jan 2018
April 2018 - Jan 2019
April 2019 - Jan 2020
Можно ли упростить этот запрос? Я не хочу UNION ALL
- когда я использую этот запрос в zoho, они ограничивают общее число UNION ALL
(139), которое я использовал в полном запросе, чтобы получить полный результат. Есть ли способ переписать приведенный выше запрос, по которому мы получаем тот же результат. Спасибо.