### 分组查询

• group by
``````select sum(price*num) total,pub from books group by pub;
``````

select后面不能再跟除group by后面的单独列。

• having
``````select sum(price*num) total,pub from books group by pub having sum(price*num)>4;
``````
• 模糊查询
``````select * from books where like pub='i_';
``````

``````select * from books where like pub='_i';
``````

``````select * from books where like pub='%i';
``````

``````select * from books where like pub='i%';
``````

``````select * from books where like pub='_i_';
``````

``````select * from books where like pub='%i%';
``````

### 表的连接

• 内连接

``````select ss.no,ww.name from ss,ww where ss.price=ww.price;
``````

``````select ss.no,ww.name from ss join ww on ss.price=ww.price;
``````
• 外连接

``````select ss.no,ww.name from ss join ww on ss.price=ww.price(+);
``````

``````select ss.no,ww.name from ss,ww where ss.price=ww.price(+);
``````

``````select ss.no,ww.name from ss join ww on ss.price(+)=ww.price;
``````

``````select ss.no,ww.name from ss,ww where ss.price(+)=ww.price;
``````

### 子查询

• 无关子查询
``````select * from ss where no in(select price from ww);
``````
• 相关子查询
``````select * from ss where price in(select price from ww where ss.price=ww.price);
``````

### 合并

``````select price from ss union select price from ww;
``````

### 根据已有表创建表

``````create table gg as select price from ss;
``````

（完）