java开发常用的sql语句,java开发中常用的SQL语句

在实际开发过程中常用的sql语句, 以user_table为例。

1)创建语句如下:

CREATE TABLE USER_TABLE

(USER_ID VARCHAR2(8),

USER_NAME VARCHAR2(20) ,

USER_SEX VARCHAR2(5) ,

USER_AGE VARCHAR2(50) ,

USER_TEL VARCHAR2(50),

CONSTRAINT MPOS_TEM_LINE_PK PRIMARY KEY (USER_ID));

2)新增语句:

insert into user_table values(1,bakehe,男,高中一班,13351210773);

3)修改语句:

update user_table set user_name=what where user_id=1

4)新增表字段:例如新增一个电话号码的字段

alter

table user_table add user_phone char(11);

例如: 新增一个字段,并且给这个字段取一个中文名

alter table reconcav.t_cbs_recon_funds_detail_tmp add CHILD_FUNDS_ID NUMBER(32);

-- Add comments to the columns

comment on column reconcav.t_cbs_recon_funds_detail_tmp.CHILD_FUNDS_ID

is 资金明细表主键ID(同步后);

5)SQL查询like语句:

select * from user_table where user_name like %bak%;

6)SQL查询之统计语句:

select user_name,sum(case when user_name=bakehe then 1 else 0 end ) bake_num,sum(case when user_name=what then 1 else 0 end ) what_num from user_table group by user_name;

7)SQL去重统计:

select count(user_id),count(distinct user_name),count(distinct user_age) from user_table;

8),范围内的sql查询:

select

* from NEWBNK where lbnk_no not in (select lbnk_no from NEWBNK_TMP);

9), SQL查询case when:

select user_id,user_name, (case user_sex when 1 then 男 when 2 then 女 else 人妖 end ) user_sex from user_table;

或者这条语句是这样的:

select user_id,user_name, (case when user_sex=1 then 男 when user_sex=2 then 女 else 人妖 end ) user_sex from user_table;

在实际开发过程中常用的sql语句, 以user_table为例。 1)创建语句如下: CREATE TABLE USER_TABLE (USER_ID VARCHAR2(8), USER_NAME VARCHAR2(20) , USER_SEX VARCHAR2(5) , USER_AGE VARCHAR2(50) , USER_TEL VARCHAR2(50), CONSTRAINT MPOS_TEM_LINE_PK PRIMARY KEY (USER_ID)); 2)新增语句: insert into user_table values(1,bakehe,男,高中一班,13351210773); 3)修改语句: update user_table set user_name=what where user_id=1 4)新增表字段:例如新增一个电话号码的字段 alter table user_table add user_phone char(11); 例如: 新增一个字段,并且给这个字段取一个中文名 alter table reconcav.t_cbs_recon_funds_detail_tmp add CHILD_FUNDS_ID NUMBER(32); -- Add comments to the columns comment on column reconcav.t_cbs_recon_funds_detail_tmp.CHILD_FUNDS_ID is 资金明细表主键ID(同步后); 5)SQL查询like语句: select * from user_table where user_name like %bak%; 6)SQL查询之统计语句: select user_name,sum(case when user_name=bakehe then 1 else 0 end ) bake_num,sum(case when user_name=what then 1 else 0 end ) what_num from user_table group by user_name; 7)SQL去重统计: select count(user_id),count(distinct user_name),count(distinct user_age) from user_table; 8),范围内的sql查询: select * from NEWBNK where lbnk_no not in (select lbnk_no from NEWBNK_TMP); 9), SQL查询case when: select user_id,user_name, (case user_sex when 1 then 男 when 2 then 女 else 人妖 end ) user_sex from user_table; 或者这条语句是这样的: select user_id,user_name, (case when user_sex=1 then 男 when user_sex=2 then 女 else 人妖 end ) user_sex from user_table;
经验分享 程序员 微信小程序 职场和发展