sql语句的简单用法 db2删除修改字段名,db2一次增加多个字段

sql语句的简单用法 db2删除修改字段名,db2一次增加多个字段

db2不能直接修改字段名,要先drop删除字段名再add新的,如下:

alter table TM_APP_FINAL_AUDIT_QUOTA  drop column  graduallyApprovalLevel
alter table TM_APP_FINAL_AUDIT_QUOTA  add column  gradually_Approval_Level varchar(12);

db2 增加多个字段

alter table TM_APP_CREDIT_INFO add column IS_FIT_PBOC_MARRIAGE varchar(1) add column IS_FIT_COM_MOBILE varchar(1) add column IS_FIT_HOME_ADDRESS_MOBILE varchar(1) add column IS_FIT_EDUCATIONAL varchar(1)

感觉麻烦就没有将表建进来,需要有基础的朋友替换相应的表和字段,谢谢

–mysql分页查询  5是查询在数据存储第5条数据20是从第五条开始的20条数据,因此显示的是6至26之间的数据

select * from tm_acl_dict where 1=1 limit 5,20    

–修改字段长度

 alter table tm_zm_score modify column CREDIT_UP_DATE varchar(32);

–移动表数据,从s2移动到tm_zm_watch_list_detail表,前提是两表的字段一致

insert into tm_zm_watch_list_detail 
    select * from s2 ;

–统计两张表的数据个数

select * from (select count(*) as c from tm_zm_watch_list_detail) as t0,
        (select count(*) from s2) as s0;

–删除表

drop table s2;  

–先去重一张表再右连接一张表,最后排序输出

select * from (
select distinct id_no from tm_zm_watch_list_detail) t0
right join cust on t0.id_no = cust.id_no
order by t0.id_no;

–先去重再计数

select count(distinct id_no) from cust;

//查询日期等于某天的

select * from tm_cis_req_prd_his t 

where t.req_date = ‘20170522’

select * from tm_zm_score t 

where t.zm_score=’666′

//大于芝麻分666的

select zm_score as score from tm_zm_score

where zm_score>666

//求和

select sum(zm_score) as score from tm_zm_score

//求平均值

select avg(zm_score) as score from tm_zm_score

//求最大值

select max(zm_score+0) as score from tm_zm_score

//求最小值

select min(zm_score+0)as score from tm_zm_score

//求数据条数

select count(zm_score) from tm_zm_score

//数字字符串排序

select * from tm_zm_score order by zm_score+0 desc

//between and用法

select * from tm_zm_score where zm_score between 6 and 66 order by zm_score+0 

//in 用法

select * from tm_zm_score where zm_score in (66)

//查询某个时间段所有大于0的数据并按芝麻分降序排列

select * from tm_zm_score where zm_score>0 and create_date between ‘2017-04-30 00:00:00’ and ‘2017-05-24 00:00:00’ order by zm_score desc

//增加一列

alter table tm_zm_score add bb varchar(11)

//删除一列

alter table tm_zm_score drop aa

//模糊查询

select * from tm_zm_score where zm_score like ‘%6%’ 

//插入数据

insert into  tm_zm_score(cust_id,org) value(’01’,’01’);

//删除数据

delete from tm_zm_score where cust_id=’02’

//更新数据

update  tm_zm_score set cust_id=’02’ where cust_id=’01’

//左连接表查询

select * from tm_zm_watch_list left join tm_zm_watch_list_detail on tm_zm_watch_list.cust_id=tm_zm_watch_list_detail.cust_id

//右连接查询

select * from tm_zm_watch_list right join tm_zm_watch_list_detail on tm_zm_watch_list.cust_id=tm_zm_watch_list_detail.cust_id

//内连接

select * from tm_zm_watch_list inner join tm_zm_watch_list_detail on tm_zm_watch_list.cust_id=tm_zm_watch_list_detail.cust_id

//索引创建

create   index q on tm_acl_dict(id)

//删除索引

drop index q on tm_acl_dict

select * from tm_acl_dict where id=1000

select zm_score as score from tm_zm_score where zm_score=66

//group by 分组查询

select type_name,count(type_name)  from tm_acl_dict group by type_name

select count(type_name) from tm_acl_dict t where t.type_name=’省’

select count(type_name) from tm_acl_dict where type_name=’省’

//case 用法

select type_name as ‘地区’,

        case type when ‘state’

                        then code else 0 end as’code’

                                from tm_acl_dict

//改变主键前要先删掉原先的主键

alter table tm_td_post_loan_monitoring_data_person_info drop PRIMARY KEY

alter table tm_td_post_loan_monitoring_data_person_info add primary key(id_number)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/106366.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • win10-11全版本下载地址MSDN纯净版ISO-20220217更新[通俗易懂]

    win10-11全版本下载地址MSDN纯净版ISO-20220217更新[通俗易懂]本文搜集整理微软官方发布的Windows10正式版镜像下载链接,从RTM原始正式版开始,按照时间倒序排列,即越往上的越新。转载:http://news.mydrivers.com/1/440/440540.htm谨记:不管从什么地方下载,文件名可以不一样,但是体积、SHA1校验码必须一致,尤其是后者,有一点不同的也不要安装。下载链接均为ed2kP2P方式,使用迅雷即可。

    2022年7月20日
    32
  • 数据库之关系模型介绍「建议收藏」

    数据库之关系模型介绍「建议收藏」本篇文章是数据库系列的第一篇文章,本系列文章是笔者在学习《数据库系统概念》这本书总结的内容,使用的数据库是mysql。关系数据库的结构关系数据库由表(table)的集合构成,每个表由唯一的名字。表中的一行代表了一组值之间的联系,而表就是这种联系的一个集合,表这个概念和数学上的关系概念是密切相关的,这也是关系数据模型名称的由来。在关系模型的术语中,关系(relation)用来指代表,元组…

    2022年7月16日
    15
  • 什么是幂等性?(幂等处理是什么意思)

    HTTP幂等方法,是指无论调用多少次都不会有不同结果的HTTP方法。不管你调用一次,还是调用一百次,一千次,结果都是相同的。HTTPGET方法HTTPGET方法,用于获取资源,不管调用多少次接口,结果都不会改变,所以是幂等的。GET/tickets#获取ticket列表GET/tickets/12#查看某个具体的ticket只…

    2022年4月17日
    102
  • TCP/IP协议详解

    TCP/IP协议详解认识HTTP协议它是互联网协议(InternetProtocolSuite),一个网络通信模型,是互联网的一个基本的构架。HTTP协议是HyperTextTransferProtocol(超文本传输协议)的缩写,是用于从万维网(WWW:WorldWideWeb)服务器传输超文本到本地浏览器的传送协议。HTTP是一个基于TCP/IP通信协议来传递数据(HTML文件,图片文件…

    2022年6月13日
    34
  • 利用IAR Timeline工具测试delay函数执行时间

    利用IAR Timeline工具测试delay函数执行时间”要把大象放冰箱,总共分几步”,呵呵,写到本篇博客的时候突然想起小品宋丹丹说的那句经典台词了(俺们东北人儿对本山大叔的作品真是滚瓜烂熟了,搞的舍友还时不时跟我学上一学),哈哈,所以就索性给题目也加上了“几步”的说法,把复杂的事情简单化,也起到吸引人眼球的作用(当然本篇也是有实料的,进来的不会让你失望的,呵呵)。咳咳,至于到底是几步,是不是传说中的“三步”来,哈哈,那还得下面分解。。。  

    2022年5月21日
    39
  • JMESPath_java中jframe怎么用

    JMESPath_java中jframe怎么用前言JMESPath是JSON的查询语言。您可以从JSON文档中提取和转换元素官方文档:https://jmespath.org/tutorial.html基本表达式JMESPath用的最多的

    2022年7月30日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号