Answer the question
In order to leave comments, you need to log in
How to pull data from two tables grouped by date?
Hello! Need help making a request.
Table structure:
transitions
id
datetime
affiliates
id
transition_id
order_sum
affiliate_sum
It is necessary to extract
COUNT(transitions.id), COUNT(affiliates.id), SUM(affiliates.affiliate_sum), SUM(affiliates.order_sum)
grouped by days (transitions.datetime)
affiliates .transition_id =
transitions.id as a result, a table of the form is required:
DATE 1 | Number of transitions.id | Number of affiliates.id | Sum affiliates.order_sum | affiliates.affiliate_sum
DATE 2 | Number of transitions.id | Number of affiliates.id | Sum affiliates.order_sum | Amount affiliates.affiliate_sum
DATE 3 | Number of transitions.id | Number of affiliates.id | Sum affiliates.order_sum | Amount affiliates.affiliate_sum
and so on
Answer the question
In order to leave comments, you need to log in
probably so
SELECT DATE_FORMAT(t.datetime, '%Y-%m-%d') AS `date`, count(t.id), count(a.id), sum(a.affiliate_sum), sum(a.order_sum)
FROM transitions AS t
INNER JOIN affiliates a ON a.transition_id = t.id
GROUP BY `date`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question