1. 程式人生 > >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)