Sql使用记录几点记录

避免重复记录插入

insert  ignore into XXXXX;

账号授权

登录mysql执行下面的操作生成bash文件,source ~/lock.txt

SELECT concat('KILL ',id,';') FROM information_schema.processlist INTO OUTFILE '~/lock.txt';GRANT ALL PRIVILEGES ON tspark.* TO 'spark'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;FLUSH PRIVILEGES;ALTER TABLE XXX ADD COLUMN version_id varchar(40) DEFAULT "V1-beta";

展示权限

show grants for 'xxx';

修改列长度

alter table `xxxx` modify column ques_type varchar(40);

查询指定版本的query

select distinct query_content from XXX where version_id='V1-beta';

查询指定字段不为null

select query_content from XXX where domain is not null;

查询指定字段为null

select query_content from XXX where domain is null;

分组查询

select query_content from XXX group by query_content having count(query_content)>1;

全表复制

insert into XXX_new( query_content,feature_describe, assert_content, group_match_id ,build_id,topic_type) select query_content,feature_describe, assert_content, group_match_id ,build_id,topic_type from XXX_manual;

对于主键重复的记录:将更新小部分其他字段:

INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;

update操作 (注意不需要转义字符)

update XXX set ner_intents='["volume_adjust"]' where ner_intents like '%volume_control%';

查询domain字段为null的记录

select * from XXX where domain is null;

使用mysql表中的部分字段更新另一张表中的部分字段

update XXX a,XXXX2 b set a.ner_intents=b.intent where a.query_content=b.query_content and a.ques_type='statement_no';

更新字段A

update XXX a,XXXX b set a.ques_type=b.ques_type where a.query_content=b.query_content;update XXXs a,XXXX2 b set a.ques_type=b.ques_type where a.query_content=b.query_content and a.feature_sub_id like '%W%';

更新字段B

update XXX a,XXXX2 b set a.ner_intents=b.intent where a.query_content=b.query_content and a.ner_intents like '%None%';

更新ques_type字段

update XXX set ques_type='STATEMENT' where ques_type is null or ques_type='';

查询重复记录

select query_content,group_match_id from XXXX group by query_content having count(query_content) > 1;

将没有重复记录的表复制到另一张表

insert into tab1 select * from tab2;select * from tab1 where query_content in (select query_content from tab1 group by query_content having count(query_content) > 1) and id not in (select id from tab1 group by query_content having count(query_content) > 1) and feature_sub_id not like '%M17%';

使用in语法进行where条件限制

select distinct name from projects where name in ('InternalChartFrame.java','NmonFileLoader.java');

复制表,插入相同数据(唯一值重复)

create table test1 like test2;insert into test1 select * from test2 on duplicate  key update test1.XX=test1.XX+N;

指定偏移数据指定行数写入

insert into test3 select * from test_result_data.tab_result_data limit 50 offset 100;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,920评论 0 13
  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 1,334评论 0 7
  • 避免重复记录插入 账号授权 登录mysql执行下面的操作生成bash文件,source ~/lock.txt 展示...
    佛系小懒阅读 243评论 0 2
  • MSSQL 跨库查询(臭要饭的!黑夜) 榨干MS SQL最后一滴血 SQL语句参考及记录集对象详解 关于SQL S...
    碧海生曲阅读 5,915评论 0 1
  • 注入攻击的分类 1.没有正确过滤转义字符 在用户的输入没有为转义字符过滤时,就会发生这种形式的注入式攻击,它会被传...
    查无此人asdasd阅读 1,842评论 0 5

友情链接更多精彩内容