mysql常用语句

数据库与表操作

显示数据库:

show databases;

切换数据库:

use  theDatabase

显示当前数据库的所有表

show tables

展示表属性:

show create table theTable

 

mysql时间操作

mysq中的时间向前移一天:

update theTable set create_time=create_time-86400 where id=566

mysql将查询的时间戳发转换为时间:

select uid,nickname,from_unixtime(create_time) from theTable where nickname="lyh";
 

 

mysql常用函数使用查询

查询数据库的记录条数:

select count(*) as total from theTable
 

 

mysql 分组查询

根据url进行分组,取durtime 最大的一条数据

select * from per_data where durTime in (select MAX(durTime) from per_data where addTime BETWEEN "2022-05-09" AND "2022-05-14" GROUP BY url) ORDER BY durTime DESC

 

Mysql替换某个字段中的字符串:

updat 表名 set 字段名=replace(字段名,'原来的内容','替换后的内容')
update wp_posts set post_content = replace(post_content,'39.105.62.250/fityoo/','www.fityoo.cn/');

Mysql查询某个字段包含某个内容:

select post_content from wp_posts where post_content like '%365天%';

多表连接查询

3表连接查询:

select t1.*,
t2.category_name,
t3.org_section_name
from devices as t1 
left join first_category as t2 on t1.first_category_id = t2.id
left join org_section as t3 on t1.org_section_id = t3.id

 查询某个时间段之间的数据:

select * from per_data where addTime BETWEEN "2022-05-10" AND "2022-05-14"

 

posted @ 2019-02-14 16:55  远洪  阅读(242)  评论(0编辑  收藏  举报