[SQL]疲れたとき...SQLを見て...hackrank問題のクリア(2)


Weather Observation Station 2


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
  • ROUND関数でSUMが使えるんですね!よかった.
  • Weather Observation Station 18


  • マンハッタン距離:2点座標(x 1,y 1)、(x 2,y 2)で表される距離|x 1-x 2|+|y 1-y 2|.
  • SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)),4)
    FROM STATION
    私は
  • の問題しか見ていないので、難しいと思いますが、少しも難しくありません.MAXMIN ABSをしっかり使えばいいだけ
  • New Companies



    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.
  • の要求は多少多いですが、
    グループBye概念+distinctについて考えてこそ、よりよく理解することができる.
  • 方正名を導入するには、まず会社表を従業員(最も基本的な表)にチェックインしたいと考えています.
  • #초안
    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
    このようにして、また群死群傷のためにずっと困難を感じているようだ.
    サブクエリを作成しますか...?ずっとうろうろしています.
    いろんなグループを探しているのでByQuery...隣にはもう一つのグループByColumが追加されました...
    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に気づかなかったので、明らかではなく、ずっとミスをして、最後に成功しました.
    组み合わせも他の基础もしっかりしている気がします.