I have two different SQL Query as below, I want to calculate the value from these two different SQL query from different tables.
-- query A(table_name_a), `date` format is StringField '20191007'
SELECT code,
sum(CASE WHEN remark IN ('111', '222', '333')
THEN t.value ELSE 0
END)/
sum(CASE WHEN remark IN ('444')
THEN t.value ELSE 0
END) AS val
FROM table_name_a
WHERE code IN ('%(code)s')
AND date BETWEEN '%(start_date)s' AND '%(end_date)s'
GROUP BY code, date
-- query B(table_name_b), `date` format is DateField '2019-10-07 00:00:00'
SELECT code,
sum(CASE WHEN remark IN ('111', '222', '333')
THEN t.value ELSE 0
END)/
sum(CASE WHEN remark IN ('444')
THEN t.value ELSE 0
END) AS val
FROM table_name_b
WHERE code IN ('%(code)s')
AND substr(regexp_replace(date,'-',''),1,8) BETWEEN '%(start_date)s' AND '%(end_date)s'
GROUP BY code, substr(regexp_replace(date,'-',''),1,8)
If I input parameter '%(code)s', '%(start_date)s' and %(end_date)s' with '00001' , '20191001' and '20191030', I got result as below
code val
1 00001 0.00798752 -- result from query A
code val
1 00001 0.00472937 -- result from query B
Now I would like to get the result by 0.00798752 + 0.00472937, I have four value from four different SQL query, can I add them together via only one SQL query?
AnalysisException: Could not resolve column/field reference: 'val2', I was stuck in this problem.........