E
E
Evgeny Shevtsov2015-03-07 11:44:03
MySQL
Evgeny Shevtsov, 2015-03-07 11:44:03

How to make 4 selections from 2 tables sorted by 1 key?

There is such a request

SELECT * FROM 
(SELECT `date`, COUNT(`hard`) AS `count` FROM `statistic` GROUP BY `date`) T1,
(SELECT `date`, COUNT(DISTINCT`hard`) AS `uniq` FROM `statistic` GROUP BY `date`) T2
WHERE T2.date = T1.date

And you need to make another query like this in the second table
SELECT * FROM 
(SELECT `date`, COUNT(`ip`) AS `count` FROM `download` GROUP BY `date`) T1,
(SELECT `date`, COUNT(DISTINCT`ip`) AS `uniq` FROM `download` GROUP BY `date`) T2
WHERE T2.date = T1.date

merge with the first one sorted by the date key.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shevtsov, 2015-03-07
@Rattlesneyk

Well, I decided probably not the right and long but working method.
The final request is like this

SELECT * FROM 
(SELECT `date`, COUNT(`hard`) AS `count` `, COUNT(DISTINCT`hard`) AS `uniq` FROM `statistic` GROUP BY `date`) T1,
(SELECT `date`, COUNT(`ip`) AS `ipcount`, COUNT(DISTINCT`ip`) AS `uniqip` FROM `download` GROUP BY `date`) T2
WHERE T2.date = T1.date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question