Write a query calculating the amount of error (i.e.: average monthly salaries), and round it up to the next integer.
SELECT CEIL(AVG(Salary)-AVG(REPLACE(CAST(Salary AS CHAR),'0','')))
FROM EMPLOYEES
*REPLACE 함수는 지정한 컬럼에서 특정 문자열을 다른 문자열로 바꾸어 주는 문자열 치환 함수.
select replace(컬럼이름A, '문자X', '문자Y')
from 테이블이름;
#SELECT 구문에서는 REPLACE 함수를 적용하여도 원본 테이블이 변경되지 않는다.
select first_name as 성명,
replace(first_name, 'e', '*') as REPLACE
from employees;

*한 칼럼의 데이터 타입을 다른 형식으로 변환시켜 보여주도록 도와주는 타입 변환 함수
CAST( 칼럼명 AS 변환하고자 하는 타입)
->
SELECT *
FROM test
ORDER BY CAST(count AS NUMBER) DESC;
CONVERT(데이터 타입, 칼럼명)
->SELECT *
FROM test
ORDER BY CONVERT(NUMBER, count) ASC;
*올림 : CEILING(값)
SELECT CEILING(940.16) --941
SELECT CEILING(942.16) --943
*버림 : FLOOR(값)
SELECT FLOOR(940.16) --940
SELECT FLOOR(942.16) --942
157.We define an employee's total earnings to be their monthly 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)earnings, COUNT(*)
FROM Employee
GROUP BY 1
ORDER BY 1 DESC
LIMIT 1;
SELECT TRUNCATE(SUM(LAT_N),4)
FROM STATION
WHERE LAT_N BETWEEN 38.7880 AND 137.2345
SELECT TRUNCATE(LAT_N,4)
FROM STATION
WHERE LAT_N <= 137.2345
ORDER BY 1 DESC
LIMIT 1;
SELECT ROUND(LONG_W,4)
FROM STATION
WHERE LAT_N <= 137.2345
ORDER BY LAT_N DESC
LIMIT 1;
SELECT ROUND(LAT_N,4)
FROM STATION
WHERE LAT_N >= 38.7780
ORDER BY 1
LIMIT 1
SELECT ROUND(LONG_W,4)
FROM STATION
WHERE LAT_N >= 38.7780
ORDER BY LAT_N
LIMIT 1
Consider and to be two points on a 2D plane.
happens to equal the minimum value in Northern Latitude (LAT_N in STATION).
happens to equal the minimum value in Western Longitude (LONG_W in STATION).
happens to equal the maximum value in Northern Latitude (LAT_N in STATION).
happens to equal the maximum value in Western Longitude (LONG_W in STATION).
Query the Manhattan Distance between points and and round it to a scale of decimal places.
SELECT ROUND((MAX(LAT_N)-MIN(LAT_N))+(MAX(LONG_W)-MIN(LONG_W)),4)MAN_D
FROM STATION;
Query the Euclidean Distance between points and and format your answer to display decimal digits.
SELECT ROUND(SQRT(POWER(MAX(LAT_N)-MIN(LAT_N),2)+POWER(MAX(LONG_W)-MIN(LONG_W),2)),4)EUC_D
FROM STATION;
SQRT() : 제곱근
POW()=POWER() : 거듭 제곱 ex) POW(2.4) : 2의 4제곱 =16
인사이트