Query the difference between the maximum and minimum populations in CITY.
SELECT MAX(POPULATION) - MIN(POPULATION)
FROM CITY
Samantha was tasked with calculating the average monthly salaries for all employees in the EMPLOYEES table, but did not realize her keyboard's key was broken until after completing the calculation. She wants your help finding the difference between her miscalculation (using salaries with any zeros removed), and the actual average salary.
Write a query calculating the amount of error (i.e.: 'actual - miscalculated'average monthly salaries), and round it up to the next integer.
SELECT CEIL(AVG(Salary) - AVG(REPLACE(CAST(Salary AS CHAR), '0', '')))
FROM EMPLOYEES
We define an employee's total earnings to be their monthly 'salary * months' worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as space-separated integers.
SELECT salary * months, COUNT(DISTINCT employee_id)
FROM Employee
where salary * months = (
SELECT salary * months
FROM Employee
order by 1 desc
limit 1
)
group by 1
가장 큰 salary * months를 구하고, 이를 조건절에 넣어 찾는 식으로 쿼리를 작성해야한다.
Query the following two values from the STATION table:
SELECT ROUND(SUM(LAT_N),2), ROUND(SUM(LONG_W),2)
FROM STATION
Query the sum of Northern Latitudes (LAT_N) from STATION having values greater than 38.7880 and less than 137.2345. Truncate your answer to decimal places.
SELECT TRUNCATE(SUM(LAT_N),4)
FROM STATION
WHERE LAT_N > 38.7880 AND LAT_N < 137.2345
Query the greatest value of the Northern Latitudes (LAT_N) from STATION that is less than 137.2345 . Truncate your answer to 4 decimal places.
SELECT TRUNCATE(MAX(LAT_N),4)
FROM STATION
WHERE LAT_N < 137.2345
Query the Western Longitude (LONG_W) for the largest Northern Latitude (LAT_N) in STATION that is less than 137.2345 . Round your answer to 4 decimal places.
SELECT ROUND(LONG_W,4)
FROM STATION
WHERE LAT_N = (SELECT MAX(LAT_N) FROM STATION WHERE LAT_N < 137.2345)
Query the smallest Northern Latitude (LAT_N) from STATION that is greater than 38.7780 . Round your answer to 4 decimal places.
SELECT ROUND(MIN(LAT_N),4)
FROM STATION
WHERE LAT_N > 38.7780
Query the Western Longitude (LONG_W)where the smallest Northern Latitude (LAT_N) in STATION is greater than 38.7780 . Round your answer to 4 decimal places.
SELECT ROUND(LONG_W,4)
FROM STATION
WHERE LAT_N = (SELECT MIN(LAT_N) FROM STATION WHERE LAT_N > 38.7780)
Consider and to be two points on a 2D plane.
Query the Manhattan Distance between points and and round it to a scale of 4 decimal places.
SELECT ROUND(ABS(DB.c-DB.a) + ABS(DB.d-DB.b),4)
FROM (
SELECT MIN(LAT_N) AS a,
MIN(LONG_W) AS b,
MAX(LAT_N) AS c,
MAX(LONG_W) AS d
FROM STATION
) DB
[12주차]리트코드: Day9( 1393) ~ Day10 (0) | 2023.03.12 |
---|---|
[11주차]해커랭크: 36~44 (0) | 2023.03.04 |
[9주차]해커랭크 16 ~ 25(Basic Select, Aggregation) (0) | 2023.02.12 |
[8주차]해커랭크 Basic Select 15 (0) | 2023.02.05 |
[7주차] 리트코드: Day5 ~ Day9(1407, 1158) (0) | 2022.12.12 |