垃圾sql

1.Minus


  MINUS运用在两个SQL语句上,先找出第一条SQL语句所产生的结果,然后看这些结果有没有在第二个SQL语句的结果中。如果有的话,那这一笔记录就被去除,而不会在最后的结果中出现。如果第二个SQL语句所产生的结果并没有存在于第一个SQL语句所产生的结果内,那这笔资料就被抛弃.

2.DISTINCT

       去重

3.ALTER

       --修改表的编码

       alter table `tablename` convert to character set utf8;

4.drop         .

        删除表

5.truncate   

        清空表

6.coalesce

  

select COALESCE (SUM(CASE WHEN type=2 THEN amount ELSE  0 END),0) as amount from order

7.正则表达式

select * from all_staff_promote_data where area_name REGEXP ('(区域){1,}')

8.is  null

9.is not null

10.group by..... having....

select
    userId as userId,
    coalesce(sum(amount),0) as amount
FROM
    order
group by
    userId
HAVING 
    SUM(amount)>10000

11.UNION all ... DISTINCT

select
    count(DISTINCT d.id) count
from
(
    select idFROM o2 where createTime between #{startTime} and  #{endTime}
UNION all
    SELECT idfrom o1 where createTime between #{startTime} and  #{endTime}
) as d

12.DATE_FORMAT

select DATE_FORMAT("2020-06-01 00:00:00","%Y年%m月%d日 %H时%i分%s秒");

select DATE_FORMAT("2020-06-01 00:00:00","  %x年%v周");

13.删除重复数据

delete from  tb_user where id not in (select * from (select  min(id) from tb_user  GROUP BY user_name) as e)

14.复制表

mysqldump oldDb -u root  -p123456 --add-drop-table | mysql newDb -u root -p123456

15.插入规则

1. insert into :插入数据,重复插入会出错
2. replace into:如果数据已经存在,就会用新值替换旧的值,没有存在相同的id,就新插入一条
3. insert ignore:如果已存在,就不会进行插入,跳过这个


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值