Query the following two values from the STATION table:
The sum of all values in LAT_N rounded to a scale of 2 decimal places.
The sum of all values in LONG_W rounded to a scale of 2 decimal places.
SELECT ROUND(SUM(LAT_N),2), ROUND(SUM(LONG_W),2)
FROM STATION
SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)),4)
FROM STATION
Given the table schemas below, write a query to print the company_code, founder name, total number of lead managers, total number of senior managers, total number of managers, and total number of employees. Order your output by ascending company_code.
#초안
SELECT C.company_code,
C.founder,
COUNT(E.lead_manager_code),
COUNT(E.senior_manager_code),
COUNT(E.manager_code),
COUNT(E.employee_code)
FROM Employee AS E
INNER JOIN Company AS C
ON E.company_code = C.company_code
GROUP BY C.company_code
ORDER BY C.company_code
이렇게 만들어놓고 그룹바이로 인한 에러때문에 계속 어려워했던것 같다.
서브쿼리를 만들어야하나..? 싶어서 계속 헤매고 있었는데
이것저것 그룹바이 쿼리를 찾다보니까.. 그냥 옆에 그룹바이 컬럼을 하나 더 늘리더라.....
SELECT C.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 AS E
INNER JOIN Company AS C
ON E.company_code = C.company_code
GROUP BY C.company_code, C.founder
ORDER BY C.company_code
duplicate를 신경쓰지 못했어서 distinct 안하고 계속 틀리다가 결국 성공 ㅠㅠ
그룹바이든 뭐든 기초가 탄탄해야 함을 느꼈다...