mysql-常用 标签: mysql 2017-04-17 15:46 43人阅读 评论(0) 收藏

创建数据库

    create database XXX;
    XXX 是库名字;

选择数据库

use XXX;
XXX 是库名字;

查看MySQL中所有的数据库

show databases;

查看数据库中所有的表

show tables;

查看表结构

desc XXX
XXX 是表名字

查看MySQL版本

MySQL -V
或
select version();

查看当前在哪个表中

select database();

增加记录

insert into 表名 (字段名,字段名) valuse(值,值);INSERT INTO 表名 VALUES (”hyq”,”M”);

删除记录

delete from 表名 where 字段名=""

修改记录

update 表名 set 字段名=值 where 字段名=值;

查询

select * from 表名 where 字段名=值;

总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1

分组查询

select 分组字段名字  count(统计的字段名字) as a from 表名 group by 分组字段名字;

左连接

select a.id,a.a,b.a,b.c from left as a left join right as b where a.id =b.id;

右链接

select a.id,a.a,b.a,b.c from left as a right join right as b where a.id =b.id;
posted @ 2017-04-17 15:46  xzcl  阅读(249)  评论(0编辑  收藏  举报