Oracle 查询语句(where,order by ,like,in,distinct)

select * from production;
alter table production
add productionprice number(7,2);

UPDATE production set productionprice=102.23
--查询语句
-- subStr 用来分割字段 1 为起始位置也就是第一个字,2位结束位置
-- 字段名称后直接跟 汉字或者其他的注释信息 为查询后的 列头
select subStr(productname,1,2) 产品名称, quantity 原价,quantity*0.9 现价 from production;


--distinct关键字查询结果去重
--当后面是多个字段时 把这些看做一个整体;
select DISTINCT productname 名称,desperation 类别 from production;

--排序ODER BY
/*
desc 降序 ;asc 升序 默认 asc
null 情况下 默认null 为最大值;
*/
select productname 名称,quantity 数量 from production ORDER BY quantity desc;

--测试null
insert into production values('17','哈哈',null,'食品','2','河南');
select productname 名称,quantity 数量 from production ORDER BY quantity desc;
select productname 名称,quantity 数量 from production ORDER BY quantity desc NULLS LAST;
select productname 名称,quantity 数量 from production ORDER BY quantity desc NULLS FIRST;

--使用别名进行排序
select productname 名称,quantity 数量 from production ORDER BY 数量 desc NULLS LAST;

--使用表达式作为排序字段
select productname 名称,quantity 数量,quantity*productionprice 总价值 from production ORDER BY 总价值 desc;
--使用查询字段的位置进行排序
select productname 名称,quantity 数量,quantity*productionprice 总价值 from production ORDER BY 3 asc;
--多个字段排序
select p.productname 名称, p.quantity 数量,p.category from production p ORDER BY 3 asc,2 desc nulls last;


--where 字句进行查询
/*
< , > , <> , != , =
*/

select p.productname 名称, p.quantity 数量,p.category from production p where subStr(p.productname,1,2)='旺旺' ORDER BY 3 asc,2 desc nulls last ;

--多个查询条件
/*
AND, OR, BETWEEN...ADN..
*/

select p.productname 名称, p.quantity 数量,p.category from production p where p.quantity BETWEEN 100 AND 300 ;

--模糊查询
/*
_ : 代替一个字符;
% :代替多个字符;
*/

select p.productname 名称, p.quantity 数量,p.category from production p where p.productname like '%米%' ORDER BY 3 asc,2 desc nulls last ;

--IN 关键字 给定字段中查找这一行的信息
select p.productname 名称, p.quantity 数量,p.category from production p where p.productname IN('旺旺','电池') ORDER BY 3 asc,2 desc nulls last ;
--对空字段的查询
select p.productname 名称, p.quantity 数量,p.category from production p where p.quantity is not null ;

转载于:https://www.cnblogs.com/charlesblogs/p/5807252.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值