人大金仓数据库的单表查询

人大金仓数据库的单表查询

查看表的内容

# 查询数据库的创建语句
\d exam.course
# 查询数据表中的数据
select * from exam.course ;
# 查询部分列
select id,name exam.couese;

在人大进仓数据库中双引号用于起别名使用而单引号则大部分用于数输出字符段使用

连接运算

# 字符串的连接
select iname || '的职称是' || title as "讲师信息" from exam.instructor;

算数运算符

# 日期运算符号
select current_date()+7 as nextwork;
# 表中数据的计算
select id+5 from t03^;

条件表达式

# 输出成绩信息成绩大于等于90 时输出高,成绩大于70并且小于90时输出中其他的输出低可以通过表达式case when 来实现
select sno,sno,score,case when score >= 90 then '高' when score <90 and score <=70 then '中' else '低' END as score_level from exam.score ;

where 子句

# where条件查询
select * from exam.score where score > 80;
# where条件查询
select * from exam.student where city='Beijing';
# 多条件查询
select * from exam.score where sno=1001 and score>85;

逻辑运算

和其他语言一样逻辑运算包括与、或、非分别使用AND OR NOT 表示

逻辑运算的优化级NOT>AND>OR

# and优先于or(输出结果为1则表示最后的结果为True)
select 1 from dual where 1=1 or 1=0 and 1=0;
# not优先于and(输出为空则表示最后结果为FLASE)
select 1 from dual where not 1=0 and 1=0;
使用括号可以改变优先级

模糊查询

# 使用百分号进行模糊查询
# 最前面的字符为B的
select * from exam.student where city like  'B%';
# 最后面字符为g的字符
select * from exam.student where city like '%g';
# 第二个字母为e
select * from exam.student where city like '_e%';

范围查询

# 时间范围查询
select * from exam.student where reg_date between '2021-01-01' and '2021-10-01';

空值查询

# 查询带有空值的数据
select * from exam.student where company is null;

order by 语句

# 升序使用asc(默认)
# 查询姓名按照入学事件查询
select sname from exam.student order by reg_date ;
# 使用关键字
select sname from exam.student order by reg_date asc;
# 使用别名进行排序
select sname as name,reg_date as date from exam.student order by date asc;
# 使用序号选择排序对象
select sname,reg_date from exam.student order by 2;
# 多列组合排序
select sname,reg_date,city from exam.student order by city,reg_date;

限制返回行数

# 获取前两行
select sname from exam.student limit 2;
# 使用子查询的方式
select * from (select rownum rn, sname,city from exam.student) where rn<=3;
# 分页查询
select sname,city from exam.student offset 3 rows fetch next 3 rows only;

去除重复值查询

select count(distinct city) from exam.student ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿龙的代码在报错

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值