分组 Group By :分组查询
(首先声明这种写法是错误的只是便于理解)select id,name,number from table group by name. 那么分组后的结果就是第二张图,然而实际上不允许出现一个格子有多个值的现象出现,因此需要对id和number列做汇总计算,如count(*)等。
过滤分组 having
having和where的区别:where是对分组前的数据进行过滤,having是对分组后的数据进行过滤。
组合查询(union)和连结查询(join):
union只是把多个select的结果简单的放到了一起(union会自动删掉重复的行,unionall则会返回所有行),join(inner join,left join ,right join)则是带有一定筛选条件在两个表中挑选符合条件的值。
增删改数据和表:
insert into table1(id,name)values(1,'tom')
delete from table where id=1
update table1 set name='Bob' where id=1
create table table1(
id int NOT NULL AUTO_INCREMENT,
name char(50) default 'jack',
primary key(id)
)
alter table table1 add phone char(20)
drop table table1
参考:《MySQL必知必会》