-2

I'm new to SQL & practicing OLYMPICS dataset on kaggle & unable to query out the result in single row. The question mark is where I am stuck

select games, count(DISTINCT r.region) AS a, count(DISTINCT r.region) AS b
from oly
JOIN regions r 
  ON oly.noc = r.noc
group by games
order by a ASC
LIMIT 1

?????

select games, count(DISTINCT r.region) AS B
from oly
JOIN regions r 
  ON oly.noc = r.noc
GROUP BY games
ORDER BY  B desc
LIMIT 1 ;
jarlh
  • 42,561
  • 8
  • 45
  • 63
AmitS
  • 1
  • 2

1 Answers1

0

As you only have 1 Row per subquery you can use CROSS JOIN

SELECT
    a1.games,a1.a,a1.b,b1.games,b1.B
FROM
(select games, count(DISTINCT r.region) AS a, count(DISTINCT r.region) AS b  from oly
JOIN regions r 
ON oly.noc = r.noc
group by games
order by a ASC LIMIT 1) a1
CROSS JOIN 
(select games, count(DISTINCT r.region) AS B  from oly
JOIN regions r 
ON oly.noc = r.noc
GROUP BY games
ORDER BY  B desc LIMIT 1 ) b1
nbk
  • 45,398
  • 8
  • 30
  • 47