查询1
来源:互联网 发布:淘宝达人广场电脑 编辑:程序博客网 时间:2024/05/21 10:05
查询里面最关键的是顺序()
1、计算列
select * from emp;-- * 表示所有-- from emp 表示从emp表查询select empno, ename from emp;select ename, sal from emp;select ename, sal*12 from emp;select ename, sal*12 as "年薪" from emp;-- as可以省略年薪必须用双引号select ename, sal*12 "年薪" from emp;select ename, sal*12 "年薪" ,sal "月薪" from emp;注意:
orale中的字段别名不允许用单引号括起来,但sql允许
为了兼容性别名统一用双引号括起。
2、distinct(不允许重复的)
select deptno from emp;--14条记录不是三条select distinct deptno from emp; --三条记录distinct deptno会过滤到重复的deptnoselect distinct comm from emp;--distinct也会过滤掉重复的nullselect distinct comm, deptno from emp;--把comm和deptno的组合进行过滤select comm, distinct deptno from emp;--逻辑上有冲突
3、between
select *from empwhere sal =5000;select *from empwhere sal >=1500 and sal <= 3000;--等价于select *from empselect *from empwhere sal in (1500,3000);--等价于select *from empwhere sal =1500 or sal = 3000;select *from empwhere sal not in (1500,3000);--等价于select *from empwhere sal !=1500 and sal != 3000;-- 数据库中不等号用 != 或 <> 推荐用<> where sal between 1500 and 3000;--查找工资小于或大于的员工的所有信息select *from empwhere sal <1500 or sal > 3000;--等价于select *from empwhere sal not between 1500 and 3000;
4、in(属于若干个孤立的值)
select *from empwhere sal in (1500,3000);--等价于select *from empwhere sal =1500 or sal = 3000;select *from empwhere sal not in (1500,3000);--等价于select *from empwhere sal !=1500 and sal != 3000;-- 数据库中不等号用 != 或 <> 推荐用<>
5、top(最前面的若干个记录)
select top 5 * from emp;select top 15 percent * from emp; -- 输出的是三个不是两个--把工资在到(包括、)之间的员工中工资最高的前三个员工所有信息输出select top 3 * from empwhere sal between 1500 and 3000order by sal desc; --desc降序不写默认升序
- 查询1
- 数据查询(1)-简单查询
- SQL连接查询1 内联接查询
- SQL连接查询1 内联接查询
- PHP天气查询1
- 查询文本框(1)
- 查询语言LINQ--1
- HQL查询(1)
- Hibernate(1)查询
- 流程查询1
- 什么是N+1查询?
- 子查询1
- JPA查询语言(1)
- hibernate查询1
- MSSQL查询方式(1)
- ContentProvider-1查询
- WS查询所有1
- hibernate n+1查询
- Ext.Net 1.x_Ext.Net.GridPanel+MSCHART案列二(易飞IQC来料批次分析与MsChart 使用双轴显示)
- XTU 1151 bus 不互相包含的最多的对的个数 DP题
- LeetCode : Surrounded Regions
- 招聘要求~
- minidump代码
- 查询1
- 为什么内置数组不支持数组之间的赋值,支持这种操作需要什么信息?
- java平台统一异常框架的设计与实现
- 那些后台进程可杀 (自学随笔)
- AS3中对于XML的使用。(待定)
- linux学习入门7——磁盘基本概念(linuxcast.net)
- extmail(dovecot配置文件注释)
- java J2se 小笔记
- android开发中如何结束所有的activity