Hi everyone,
I’d like to join two graphs of two different tables, graph 1 plots the commission sum and the cashback sum of the last 13 months per month, and graph 2 does the same for pay out. However I’d rather want these three in 1 graph, but I can’t figure out how. The 2 working sql’s look as following;
SELECT str_to_date(concat(date_format(transactions
.created_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) AS created_at
, sum(transactions
.commission
) AS sum
, sum(transactions
.cashback
) AS sum_2
FROM transactions
WHERE str_to_date(concat(date_format(transactions
.converted_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) BETWEEN str_to_date(concat(date_format(date_add(now(), INTERVAL -13 month), ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
AND str_to_date(concat(date_format(now(), ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
GROUP BY str_to_date(concat(date_format(transactions
.created_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
ORDER BY str_to_date(concat(date_format(transactions
.created_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) ASC
SELECT str_to_date(concat(date_format(payouts
.exported_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) AS exported_at
, sum(payouts
.amount
) AS sum
FROM payouts
WHERE str_to_date(concat(date_format(payouts
.exported_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) BETWEEN str_to_date(concat(date_format(date_add(now(), INTERVAL -13 month), ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
AND str_to_date(concat(date_format(now(), ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
GROUP BY str_to_date(concat(date_format(payouts
.exported_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’)
ORDER BY str_to_date(concat(date_format(payouts
.exported_at
, ‘%Y-%m’), ‘-01’), ‘%Y-%m-%d’) ASC
is there any way to join graph 1 and 2, by joining the sql, or is there an easier way?
thanks in advance