Answer the question
In order to leave comments, you need to log in
How to use GROUP BY in one QUERY with multiple SELECT?
Hello!
Roughly speaking, there is such a request:
SELECT
(SELECT COUNT(*) FROM `l_sites`) AS tot_user,
(SELECT COUNT(*) FROM `l_users`) AS tot_user2,
(SELECT COUNT(*) FROM `l_leads`) AS tot_user3
SELECT `date`, COUNT(*) AS tot_user FROM `l_sites` GROUP BY `date`
SELECT `date`, COUNT(*) AS tot_user2 FROM `l_users` GROUP BY `date`
SELECT `date`, COUNT(*) AS tot_user3 FROM `l_leads` GROUP BY `date`
Answer the question
In order to leave comments, you need to log in
SELECT `date`, COUNT(*) AS cnt, 'tot_user' as user FROM `l_sites` GROUP BY `date`
union all
SELECT `date`, COUNT(*) AS cnt, 'tot_user2' as user FROM `l_users` GROUP BY `date`
union all
SELECT `date`, COUNT(*) AS cnt, 'tot_user3' as user FROM `l_leads` GROUP BY `date`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question