Code нельзя убирать.
После выполнения моего запроса, у вас уже есть все данные, теперь их нужно сгруппировать (без Code):
select
t3.Continent,
t3.Region,
sum(t3.Countries),
sum(t3.LifeDuration),
sum(t3.Population),
sum(t3.Cities),
sum(t4.Languages)
from
(
select
t1.Code,
t1.Continent,
t1.Region,
t1.Countries,
t1.LifeDuration,
t1.Population,
t2.Cities
from
(
select
Code,
Continent,
Region,
count(Name) as Countries,
ROUND(AVG(LifeExpectancy), 2) as LifeDuration,
SUM(Population) as Population
from country
group by Code,Continent,Region
) t1 left join
(
select
CountryCode,
count(Name) as Cities
from city
group by CountryCode
) t2 on t2.CountryCode = t1.Code
) t3 left join
(
select
CountryCode,
count(Language) as Languages
from countrylanguage
) t4 on t4.CountryCode = t3.Code
SELECT t1.post_id, SUM(t1.dl)
FROM wp_day_download t1
INNER JOIN
( SELECT DISTINCT object_id FROM wp_term_relationships t2
INNER JOIN wp_term_taxonomy t3 ON t3.term_taxonomy_id = t2.term_taxonomy_id AND t3.term_id = 179
) t4 ON t4.object_id = t1.post_id
WHERE t1.date >= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -7 DAY)
GROUP BY t1.post_id
Станислав Кукаев
переморочено как раз здесь - ORDER BY date_add >= NOW() DESC, id DESC,
можно сократить - ORDER BY id DESC
я думаю результат запроса будет такой же.
select t.*
from
(
select
c1.user_id as uid,
c1.contact_id as cid
from contacts c1
outer join contacts c2 on c1.id=c2.id
where c1.user_id=x and c2.user_id=y
) t
where t.uid = х
;
После выполнения моего запроса, у вас уже есть все данные, теперь их нужно сгруппировать (без Code):
select
t3.Continent,
t3.Region,
sum(t3.Countries),
sum(t3.LifeDuration),
sum(t3.Population),
sum(t3.Cities),
sum(t4.Languages)
from
(
select
t1.Code,
t1.Continent,
t1.Region,
t1.Countries,
t1.LifeDuration,
t1.Population,
t2.Cities
from
(
select
Code,
Continent,
Region,
count(Name) as Countries,
ROUND(AVG(LifeExpectancy), 2) as LifeDuration,
SUM(Population) as Population
from country
group by Code,Continent,Region
) t1 left join
(
select
CountryCode,
count(Name) as Cities
from city
group by CountryCode
) t2 on t2.CountryCode = t1.Code
) t3 left join
(
select
CountryCode,
count(Language) as Languages
from countrylanguage
) t4 on t4.CountryCode = t3.Code
group by t3.Continent,t3.Region