1. order by排序
排序中有两种:asc是升序,desc是降序
升序:
mysql> select * from person order by age ASC;
降序:
mysql> select * from person order by age desc;
2. group by分组将数据表按名字分组并每个人的记录:
mysql> select name, count(*) from person group by name;
+---------+----------+
| name | count(*) |
+---------+----------+
| eason | 1 |
| jay | 1 |
| liuhuan | 1 |
| naying | 1 |
+---------+----------+
3. mysql的连接使用,是相对前面来讲复杂一点的东西:
连接分为三种:
inner join:表示连接后,取交集(两个表中字段匹配的部分);(内连接)
left join:表示连接后,取交集和左边表部分;(左连接)
right join:表示连接后,取交集和右边部分;(右连接)
inner join:
mysql> select * from person a inner join sing b on a.age = b.age;
取表person 和 sing,命名为a和b,挑选出age匹配部分的数据
left join:
mysql> select * from person a left join sing b on a.age = b.age;
挑选出连接后左边数据表,其余部分用null填充
left join:
mysql> select * from person a right join sing b on a.age = b.age;
挑选出连接后右边数据表,其余部分用null填充