728x90 MySQL19 [MySQL] 그룹별 누적 합계 구하기 SQL 쿼리를 활용하여 DB에 있는 데이터를 추출하다보면, 그룹별로 누적 합계를 계산해야 할 때가 있습니다. 최근, SQL 관련 업무를 진행하다 앞서 말한 상황이 발생해서 문제를 해결하기 위해 여러 사이트를 참고하여 포스팅을 해보겠습니다. ※ Oracle은 PARTITION BY / ROW_NUMBER OVER() 등 함수를 통하여 이러한 기능을 쉽게 구현할 수 있습니다. 하지만, 낮은 버전의 MySQL에는 이러한 기능이 부족하여 변수 설정을 통해 누적 합계를 구해야 합니다. (최신 버전, 8.0 이상에서는 앞서 말씀드린 함수가 사용 가능하게 업데이트 된 것으로 알고 있습니다.) 개인적으로 공부할SQL 쿼리를 활용하여 DB에 있는 데이터를 추출하다보면, 그룹별로 누적 합계를 계산해야 할 때가 있습니다. .. 2021. 4. 11. [leetcode] MySQL > 596. Classes More Than 5 Students 문제. leetcode database 180. Consecutive Numbers SQL Schema & Explanation There is a table courses with columns: student and class Please list out all classes which have more than or equal to 5 students. For example, the table: +---------+------------+ | student | class | +---------+------------+ | A | Math | | B | English | | C | Math | | D | Biology | | E | Math | | F | Computer | | G | Math | |.. 2021. 2. 8. [leetcode] MySQL > 180. Consecutive Numbers 문제. leetcode database 180. Consecutive Numbers SQL Schema & Explanation Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 1 | | 6 | 2 | | 7 | 2 | +----+-----+ For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times. +--.. 2020. 9. 14. [leetcode] MySQL > 183. Customers Who Never Order 문제. leetcode Database 183. Customers Who Never Order SQL Schema & Explanation Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything. Table: Customers. +----+-------+ | Id | Name | +----+-------+ | 1 | Joe | | 2 | Henry | | 3 | Sam | | 4 | Max | +----+-------+ Table: Orders. +----+------------+ | Id |.. 2020. 9. 12. [leetcode] MySQL > 185. Department Top Three Salaries leetcode Database 185. Department Top Three Salaries SQL Schema & Explanation The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 85000 | 1 | | 2 | Henry | 80000 | 2 | | 3 | Sam | 60000 | 2 | | 4 | Max | 90.. 2020. 9. 11. [leetcode] 177. Nth Highest Salary (MySQL) 문제. leetcode Database 177. Nth Highest Salary SQL Schema & Explanation Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return nu.. 2020. 9. 10. 이전 1 2 3 4 다음 728x90