数据库学习笔记

来源:互联网 发布:php guzzle 异步请求 编辑:程序博客网 时间:2024/06/04 17:48
1、建数据库:create database lmm_lz;

2、 建表:create table lmm_lz(date datetime not null,event char not null,salary int not null);

3、使用数据库:use lmm_lz(可以没有分号)

4、进入lmm_lz数据库:mysqlD lmm_lz-u rootp

5、插入记录: insert into lmm_lz values(‘2017-3-16’,'work',208)

6、添加新列:alter table lmm_lz add expense int;

7、修改数据库/表的编码方式:alter tabledatabase lmm_lz character set utf8;

8、显示表的信息:describe lmm_lz;

9、显示数据库中的表:describe lmm_lz;

10、修改列的信息:alter table lmm_lz change expense expense int default 0;

11、清空表:

delete from lmm_lz;

12、更新表的数据:update lmm_lz set expense=96,salary=0 where event='ticket';

13、删除数据库/表:drop database/table lmm_lz;

14、删除重复行:1.select  distinct * from lmm_lz;

delete from lmm_lz  where event in  (select event from (select count(event)  from lmm_lz group by event having count(event) > 1) as tab);

15、输出10行:select * from lmm_lz limit 10;(注意mysql不支持top n语句)

16、排序:select * from lmm_lz order by date ;

17、计算行的总和:select count(*)  from lmm_lz;

18、计算数据的总和:select sum(salary) from lmm_lz;

19、计算数据的平均值: select avg(expense) from lmm_lz;

20、计算数据的最大最小值:select max/min(expense) from lmm_lz;

21、表的重命名:rename table lmm_lz1 to lmm_lz_1;    或alter table lmm_lz_1 rename lmm_lz;


关于数据库中时间的格式:



0 0