<HackerRank>
-
Weather Observation Station 18<HackerRank> 2023. 7. 17. 21:25
Weather Observation Station 18 -- MYSQL WITH POINTS as ( SELECT MIN(LAT_N) AS a, MIN(LONG_W) AS b, MAX(LAT_N) AS c, MAX(LONG_W) AS d FROM STATION ) SELECT ROUND(ABS((a-c)+(b-d)),4) FROM POINTS -- MS SQL SERVER SELECT CAST(ABS((max(LAT_N) - min(LAT_N)) + (max(LONG_W) - min(LONG_W))) AS decimal(10,4)) FROM station -- ORACLE select round(max(LAT_N)-min(LAT_N)+max(LONG_W)-min(LONG_W),4) from STATION..
-
NEW Companies<HackerRank> 2023. 7. 14. 21:13
NEW Companies -- MYSQL SELECT e.company_code, c.founder, count( DISTINCT e.lead_manager_code ), count( DISTINCT e.senior_manager_code ), count( DISTINCT e.manager_code ), count( DISTINCT e.employee_code ) FROM Employee e, Company c WHERE e.company_code = c.company_code GROUP BY company_code, founder; -- oracle, db2 select c.company_code, c.founder, count(distinct e.lead_manager_code), count(dist..
-
Binary Tree Nodes<HackerRank> 2023. 7. 12. 21:36
Binary Tree Nodes -- DB2, ORACLE SELECT N, (CASE WHEN P IS NULL THEN 'Root' WHEN N NOT IN (SELECT NVL(P,0) FROM BST) THEN 'Leaf' ELSE 'Inner' END) FROM BST ORDER BY N; -- MYSQL, MS SQL SERVER SELECT N , CASE WHEN p IS NULL THEN "Root" WHEN N IN (SELECT DISTINCT P FROM BST) THEN "Inner" ELSE "Leaf" END FROM BST ORDER BY N;
-
The PADS<HackerRank> 2023. 7. 10. 21:45
The PADS -- DB2 SELECT (name || '(' || SUBSTR(occupation,1,1) || ')') FROM occupations ORDER BY name; SELECT ('There are a total of ' || COUNT(occupation) || ' ' || LOWER(occupation) || 's' || '.') FROM occupations GROUP BY occupation ORDER BY COUNT(occupation), occupation ASC; -- MYSQL SELECT CONCAT(Name, '(', (SUBSTRING(Occupation, 1, 1)), ')') FROM OCCUPATIONS ORDER BY Name ASC; SELECT CONCAT..