Mysql学习笔记

  1. group by(注意使用位置在where条件后面)
select * from user where name group by name;
  1. with rollup(可以实现在分组统计的基础上,再进行相同的统计(sum,avg,count...))
select coalesce(name,'总数'),sum(singin) as singin_count from employee group by name with rollup;
  1. union(用于连接两个以上select语句的结果到一个结果集合中,默认会删除重复的数据)
select country from websites 
union
select country from apps
order by country;
  1. insert into ... select (复制表)
  2. select ... into outfile (导出数据)
  • 在下面的例子中,生成一个文件,各值用逗号隔开。这种格式可以被许多程序使用:
select a,b,a+b into outfile '/tmp/result.text'
fields terminated by ',' optionally enclosed by '"'
from test_table
  1. 导入
  • mysql命令导入
  • source命令导入
  • 使用load data导入数据
  • 使用mysqlimport导入数据

你可能感兴趣的:(Mysql学习笔记)