基础语句
select * from tb1;
select * from tb1 limit 3;
select name,age from tb1; select name,age from tb1 where age = 25;
select * from tb1 where age != 28;
select * from tb1 where age >= 25 and age <=28;
select name,age from tb1 where age between 25 and 28;
select * from tb1 where age = 25 or age = 28;
select * from tb1 where age not between 25 and 28;
select * from tb1 where age < 25 or age > 28; select * from tb1 where name like 'j%';
select * from tb1 where name like 't__';
select * from tb1 where name rlike '^t.*'; select * from tb1 where age in (22,23,24,25);
select * from tb1 where age not in (28,33,43); select * from tb1 order by age;
select * from tb1 order by age asc;
select * from tb1 order by age desc;
select * from tb1 order by age desc,name asc; select distinct age from students; #去重查询
select name as StuName,age from tb1;
分组与聚合
select gender,sum(age) from students group by gender;
select classid,avg(age) as avgage from students group by classid having avgage > 25;
select sum(age) from students where age > 19 group by gender;
多表查询
# 交叉连接
select * from t1 cross join t2 cross join t3;
select * from t1,t2,t3;
# 内连接
select * from t1 inner join t2 on t1.t1id=t2.t2id;
select * from t1,t2 where t1.t1id=t2.t2id;
# 外连接
select * from t1 right outer join t2 on t1id=t2id;
select * from t1 left outer join t2 on t1id=t2id;
select * from t1 right join t2 on t1id=t2id;
select * from t1 left join t2 on t1id=t2id;
#联合查询
select * from t1 union select * from t2; #重复数据合并
select * from t2 union all select * from t4; #显示重复记录
#全连接
>

9、select 语句的更多相关文章

  1. oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数

        花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...

  2. CREATE TABLE 表名 AS SELECT 语句

    1.新表不存在复制表结构即数据到新表 ? 1 2 create table new_table select * from old_talbe; 这种方法会将old_table中所有的内容都拷贝过来, ...

  3. 优化Select 语句的原则

    优化Select 语句的原则 -摘抄<SQL Server 2005 性能监测与优化> Select 语句是数据库应用系统中最常用的语句之一,Select 语句设计的好坏直接影响到应用程序 ...

  4. SQL指南-SELECT语句

    SELECT 语句 SELECT 语句用于从表中筛选数据.列表结果存储于一个结果表中(称作result-set) 语法 SELECT column_name(s)FROM table_name 注意: ...

  5. SQL Server(三):Select语句

      1.最基本的Select语句: Select [Top n [With Ties]] <*|Column_Name [As <Alias>][, ...n]> From & ...

  6. SQL SELECT 语句

      本章讲解 SELECT 和 SELECT * 语句. SQL SELECT 语句 SELECT 语句用于从表中选取数据. 结果被存储在一个结果表中(称为结果集). SQL SELECT 语法 SE ...

  7. Select语句也会引起死锁

    项目上线,准备验收前出现了一个严重的问题:很多select语句作为死锁的牺牲,大部分报表无法打开.这个问题影响范围很大所有的报表都无法访问,而我们的报表是放在电视上面轮播的,电视放在工厂里面,所以出现 ...

  8. 一条Select语句丛生到死的处理过程

    以一条普通的“select * from table order by …”语句为例.图2-21中显示为该语句在数据库中各个组件之间的处理过程,各个步骤分别代表: (1)select语句通过网络传送给 ...

  9. select语句for update---转载

    作用: Select…For Update语句的语法与select语句相同,只是在select语句的后面加FOR UPDATE [NOWAIT]子句. 该语句用来锁定特定的行(如果有where子句,就 ...

  10. 如何阻止SELECT * 语句

    我们每个人都知道是个不好的做法,但有时我们还是要这样做:我们执行SELECT * 语句.这个方法有很多弊端: 你从你的表里返回每个列,甚至后期加的列.想下如果你的查询里将来加上了VARCHAR(MAX ...

随机推荐

  1. malloc realloc calloc free

    自上次发现自己对这几个C函数不熟悉,就打算抽空整理一下,也就现在吧.这几个函数都是跟堆内存打交道的,还有一个好玩的函数--alloca,它是跟栈内存打交道的,我想留在以后研究出好玩点的来,再专门为其写 ...

  2. Servlet小案例总结

    亮点: 没有使用任何框架,视图层和业务层使用Servlet技术进行交互,持久层用java的jdbc工具类进行数据交互 较为底层,比较基础的工具类比较多,比如: BeanFactory工具类使用dom4 ...

  3. Runnable和Thread实现多线程的区别(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17161237 Java中实现多线程有两种方法:继承Thread类.实现Runnable接口 ...

  4. redis高可用 - 主从复制

    工作需要,调研了一下redis的复制实现.在2.8版本之前和之后,复制方式有所不同.2.8之前的复制方式对于初次复制数据没有问题,对于断连接重新复制比较耗性能,因为都是全量复制.2.8之后对断线重连做 ...

  5. Linux 系统配置

    centos 7 防火墙和端口配置开启redis端口,修改防火墙配置文件 vi /etc/sysconfig/iptables 加入端口配置 -A RH-Firewall-1-INPUT -m sta ...

  6. 基于weui的一个小插件

    移动端项目当中大量的使用了weui,为了减少工作量,方便修改,自己写了个小插件,暂时只有toast和dialog部分,可能会更新actionSheet等其他部分 更新一个手机端预览的二维码,就直接放项 ...

  7. p4980 polya定理

    传送门 分析 orz ymh 代码 #include<iostream> #include<cstdio> #include<cstring> #include&l ...

  8. OSG相机与视图

    转自:http://blog.csdn.net/wang15061955806/article/details/51603083 相机与视图     osg::Camera类用来管理OSG中的模型—— ...

  9. CentOS 7.2配置Apache服务httpd(上)

    http://www.jb51.net/article/97434.htm 二.安装Apache httpd 安装httpd以配置Web服务器, HTTP使用80 / TCP ? 1 2 3 4 5 ...

  10. CodeForces 342C Cupboard and Balloons (几何问题)

    题意:给定一个 r 和 h,r 是上面那个半球的半径,h 是下面那个圆柱的高度,然后有一些半径为 r/2的气球,问你最多能放几个. 析:根据题意,很容易知道,先从下面往上放,两个两个的放,放到不能放的 ...