a는 북위 최소값 / b는 북위 최대값 / c는 경도 최소값 / d는 경도 최대값이다.
이 때, P1(a,c) 와 P2(b,d) 사이의 유클리드 거리를 소수점 4자리에서 반올림하여 구하기
유클리드 거리 구하는 공식 :
SELECT
ROUND(SQRT(POW((MAX(LAT_N) - MIN(LAT_N)), 2) + POW((MAX(LONG_W) - MIN(LONG_W)), 2)), 4) AS Eucl_d
FROM
STATION
;
SET @num = -1;
SELECT
ROUND(AVG(LAT_N), 4) AS median
FROM
(
SELECT
@num := @num + 1 AS row_num,
LAT_N
FROM
STATION
ORDER BY
LAT_N
) AS sub
WHERE
row_num IN (FLOOR(@num/2), CEIL(@num/2))
;
SELECT
ROUND(AVG(population)) AS avg_pop
FROM
CITY
;
SELECT
SUM(population) AS sum_pop
FROM
CITY
WHERE
countrycode = 'JPN'
;
SELECT
MAX(population) - MIN(population) AS diff
FROM
CITY
;
SELECT
CEIL(AVG(salary) - avg(replace(salary, '0', '')))
FROM
employees
;
A
, B
, C
는 삼각형의 각 변 길이를 나타낸다.SELECT
CASE WHEN A + B > C
THEN
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A != B AND B != C AND A != C THEN 'Scalene'
ELSE 'Isosceles' END
ELSE 'Not A Triangle' END
FROM
TRIANGLES
;
There are a total of [occupation_count] [occupation]s.
SELECT
CONCAT(name, '(', LEFT(occupation, 1), ')')
FROM
occupations
ORDER BY
name
;
SELECT
CONCAT('There are a total of ', COUNT(*), ' ', LOWER(occupation), 's.')
FROM
occupations
GROUP BY
occupation
ORDER BY
COUNT(*)
;
SELECT
SUM(CITY.population)
FROM
CITY
INNER JOIN
COUNTRY
ON CITY.COUNTRYCODE = COUNTRY.CODE
WHERE
CONTINENT = 'Asia'
;
SELECT
NAME
FROM
CITY
INNER JOIN
COUNTRY
ON CITY.COUNTRYCODE = COUNTRY.CODE
WHERE
CONTINENT = 'Africa'
;
SELECT
CONTINENT,
FLOOR(AVG(CITY.POPULATION))
FROM
COUNTRY
INNER JOIN
CITY
ON COUNTRY.CODE = CITY.COUNTRYCODE
GROUP BY
CONTINENT
;
SELECT
CASE WHEN GRADE > 7 THEN NAME
ELSE NULL END,
GRADE,
MARKS
FROM
STUDENTS
INNER JOIN
GRADES
ON MARKS >= MIN_MARK AND MARKS <= MAX_MARK
ORDER BY
GRADE DESC,
NAME,
MARKS DESC
;
SELECT
h.hacker_id,
h.name
FROM
submissions AS s
INNER JOIN
challenges AS c
ON s.challenge_id = c.challenge_id
INNER JOIN
difficulty AS d
ON c.difficulty_level = d.difficulty_level
INNER JOIN
hackers AS h
ON s.hacker_id = h.hacker_id
WHERE
s.score = d.score
AND c.difficulty_level = d.difficulty_level
GROUP BY
h.hacker_id,
h.name
HAVING COUNT(s.hacker_id) > 1
ORDER BY
COUNT(s.hacker_id) DESC,
s.hacker_id
;