update salary
set sex = case sex
when 'm' then 'f'
else 'm'
end;
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
select a.Name as Employee
from Employee as a inner join Employee as b
on a.ManagerId = b.Id
where a.Salary > b.Salary
+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
DELETE p1
FROM Person p1 inner join Person p2
on p1.Email = p2.Email AND p1.Id > p2.Id
+---------+------------+------------------+
| Id(INT) | Date(DATE) | Temperature(INT) |
+---------+------------+------------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+---------+------------+------------------+
+----+
| Id |
+----+
| 2 |
| 4 |
+----+
select a.Id
from Weather as a inner join Weather as b
on datediff(a.Date,b.Date) = 1 and a.Temperature > b.Temperature
select class
from courses
group by class
having count(distinct student) >= 5
网友评论