UNION 과 UNION ALL의 차이
UNION
은 두 쿼리의 결과에서 중복되는 값을 삭제하여 나타냅니다.
UNION ALL
은 두 쿼리의 결과에서 중복되는 값을 모두 …
UNION
은 두 쿼리의 결과에서 중복되는 값을 삭제하여 나타냅니다.
UNION ALL
은 두 쿼리의 결과에서 중복되는 값을 모두 …
Input:
Teams table:
+---------+-----------+
| team_id | team_name |
+---------+-----------+
| 1 | Ajax |
| 4 | Dortmund |
| 6 | Arsenal |
+---------+-----------+
Matches table:
+--------------+--------------+-----------------+-----------------+
| home_team_id | away_team_id | home_team_goals | away_team_goals |
+--------------+--------------+-----------------+-----------------+
| 1 | 4 | 0 | 1 |
| 1 | 6 | 3 | 3 |
| 4 | 1 | 5 | 2 |
| 6 | 1 | 0 | 0 |
+--------------+--------------+-----------------+-----------------+
Output:
+-----------+----------------+--------+----------+--------------+-----------+
| team_name | matches_played | points | goal_for | goal_against | goal_diff |
+-----------+----------------+--------+----------+--------------+-----------+
| Dortmund | 2 | 6 | 6 …
UPDATE tree
SET seq = 1
WHERE id IN (
SELECT t1.id
FROM …
MySQL Documentation 13.6.5.8 WHILE Statement
[begin_label:] WHILE search_condition DO
statement_list
END WHILE [end_label]
CREATE PROCEDURE dowhile()
BEGIN
DECLARE v1 INT …
아래와 같은 쿼리를 날리면 2 | NULL
이 나올 것 같지만 아니다.
OR name IS NULL
도 넣어줘야 된다.
Department table:
+----+-------+
| id | name |
+----+-------+
| 1 | IT …
Input:
Logs table:
+----+-----+
| id | num |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
+----+-----+
Output:
+-----------------+
| ConsecutiveNums |
+-----------------+
| 1 |
+-----------------+
Explanation: 1 is the only number that appears consecutively for at least three times.
Input:
Accounts table:
+----+----------+
| id | name |
+----+----------+
| 1 | Winston |
| 7 | Jonathan |
+----+----------+
Logins table:
+----+------------+
| id | login_date |
+----+------------+
| 7 | 2020-05-30 |
| 1 | 2020-05-30 |
| 7 | 2020-05-31 |
| 7 | 2020-06-01 |
| 7 | 2020-06-02 |
| 7 | 2020-06-02 |
| 7 | 2020-06-03 |
| 1 | 2020-06 …