查询语句

一、基础查询语句
增:insert into 表名(a,b,c)values ('', '','');
insert into [user](id,serial,username,passward) values('aba35738-1f00-4eb5-9657-0377ea0f1afb','janny','janny','12345678')
 
 
删:delete from 表名 where a = 'a';
 
改:update 表名 set a = ‘a’ where b = ‘b’;
 
查:select * from 表名
联表查询:
select 字段名 from 表1,表2 where 表1.id = 表2.id and 表1.名称=‘’
select 字段名 from 表1 join 表2 on 表1.id = 表2.id
select 字段名 from 表1 in (select 字段名 from 表2 where 表2.z = ‘’)
 
实例:
联表查询语句
1.使用 join on
Select a.id as "编号",a.account_id ,a.type,a.reference_data,a.create_user_id,a.create_time,a.amount,a.id
from account_capital_activity  as a join account on a.account_id in
(Select id from account where [name] like 'janny%')
2.使用where
Select account_capital_activity.id,account_capital_activity.account_id,account_capital_activity.type,account_capital_activity.reference_data,account_capital_activity.create_user_id,account_capital_activity.create_time,account_capital_activity.amount,account.id
from account_capital_activity , account where account_capital_activity.account_id in
(Select id from account where [name] like 'janny%')
 
 
二、 特殊查询语句
 
1、distinct 不同的,去掉重复的值
SELECT DISTINCT 列名称 FROM 表名称
2、top 筛选表数据
select top(100)* from custom_value
 
 3、as 别名
select ename,salary *13 as "年薪"  from emp;
 
4、null 值的影响
使用NVL 将空值转换为0
select ename,salary *13 + nvl(comm,0) "年收入" from emp;
 
5、字符拼接 ||
select ename ||' '|| job "姓名和职位" from emp
 
6、排序  order by
select a, b from table_c
order by a asc/desc ,b asc,desc
 
 
7、表名或列名与关键字 相同时使用 []
select * from [user]
 
 
8、and  or  not 逻辑运算符限定条件
 
9、between ~ and ~
select * from emp where sal between 1500 and 2000;
 
10、in 和 not in (list)
 
11、 is null  和 is not null
不能使用 =null 或<>null
 
12、模糊查询 like
通配符
%:代表0个或多个字符
—:下划线匹配任意一个字符
 
 
 
 
 
 
 
 

posted on 2020-09-29 18:08  Da_luo  阅读(152)  评论(0编辑  收藏  举报