一些常用的sql语句

1.权限更改时,给有相应页面权限且没有14平台权限的人,加上14平台权限
update `user` set `group`=CONCAT(`group`,',14')
WHERE power LIKE '%4017%' and `group` NOT LIKE '%14%'

2.多表联合修改
UPDATE A a,B b
SET b.LTV=a.LoginCnt
where a.Log_Date='2016-3-11' and b.Log_Date=a.Log_Date and b.Channel_ID=a.Channel_ID and b.Server_ID=a.Server_ID

3.查看表的创建信息
SHOW CREATE TABLE A 

4.选择上一周的周日
select convert(subdate(curdate(),date_format(curdate(),'%w')+7),char(10))
本周周日加0
select convert(subdate(curdate(),date_format(curdate(),'%w')+0),char(10))

5.选择每10秒的数据
select *,convert(concat(CONVERT(log_time,char(18)),'0'),datetime)
from log_online 
WHERE log_time BETWEEN '2016-6-4' AND '2016-6-5'
order by 1

6. 导出数据的表
mysqldump -h 10.10.39.170 -uroot -p xxx dim_action > dim_action.sql

7. 查看数据库中表的数量
SELECT count( * ) FROM information_schema.tables WHERE TABLE_SCHEMA = 'XXX';

8. 查看数据库中存储过程的数量
select count(*) from mysql.proc where db = 'XXXX' and `type` = 'PROCEDURE';

9. 查看数据库中存储过程的名称
select `name` from mysql.proc where db = 'XXX' and `type` = 'PROCEDURE';

10. 添加单个多列索引,优化查询速度
ALTER TABLE report_daily_keep ADD INDEX Log_Date(Log_Date,Channel_ID,Server_ID)
alert table 表名 add index 索引名(列名1,列名2,列名3...)

11.删除索引
ALTER TABLE XXX DROP INDEX Log_Date
alert table 表名 drop index 索引名

12. mysql 查询的结果插入到另外的表
INSERT into user_logout_identify_copy(username,is_logout)
SELECT `name`,1 from `user`

13. 先求出两个表格的差集,然后把差集插入到另一个表中
INSERT into A_column(column_name, translate_name)
( SELECT * from B_column WHERE column_name not in ( SELECT column_name from A_column) )


不断更新中….

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值