테이블
Weather
id | recordDate | temperature |
---|---|---|
1 | 2015-01-01 | 10 |
2 | 2015-01-02 | 25 |
3 | 2015-01-03 | 20 |
4 | 2015-01-04 | 30 |
문제
- 전날 보다 온도가 오른 튜플만 뽑으시오
답
SELECT w2.id
FROM Weather w1, Weather w2
WHERE w1.recordDate = DATE_SUB …
id | recordDate | temperature |
---|---|---|
1 | 2015-01-01 | 10 |
2 | 2015-01-02 | 25 |
3 | 2015-01-03 | 20 |
4 | 2015-01-04 | 30 |
SELECT w2.id
FROM Weather w1, Weather w2
WHERE w1.recordDate = DATE_SUB …
MySQL Documentation 13.6.5.5 LOOP Statement
SELECT CONCAT_WS('/', 'one', 'two', 'three')
=> one/two/three
docker-compose up -d docker exec -it mysql_sample bash cd usr/src/test_db mysql -uroot -pMyPassword -t < employees.sql
read moreSELECT ADDDATE('2022-01-02', INTERVAL 31 DAY)
=> 2022-02-02
SELECT ADDDATE('2022-01-02', 31)
=> 2022-02-02
SELECT ADDTIME('2021-01-01 00:00:00', '100')
=> 2021-01-01 00:01:00
SELECT ADDTIME …
Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
Output:
+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
SELECT …
Input:
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
n = 2
Output:
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
id | name |
---|---|
1 | Joe |
2 | Henry |
3 | Sam |
4 | Max |
id | customerId |
---|---|
1 | 3 |
2 | 1 |
SELECT c.name AS Customers
FROM Customers …
Input:
Department table:
+------+---------+-------+
| id | revenue | month |
+------+---------+-------+
| 1 | 8000 | Jan |
| 2 | 9000 | Jan |
| 3 | 10000 | Feb |
| 1 | 7000 | Feb |
| 1 | 6000 | Mar |
+------+---------+-------+
Output:
+------+-------------+-------------+-------------+-----+-------------+
| id | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |
+------+-------------+-------------+-------------+-----+-------------+
| 1 | 8000 | 7000 | 6000 | ... | null |
| 2 | 9000 | null | null | ... | null |
| 3 | null | 10000 | null | ... | null |
+------+-------------+-------------+-------------+-----+-------------+
Explanation: The …