select upper(n_id) from nrc_news;
select left(n_content,1) from nrc_news;
select len(n_content) from nrc_news;

left() 返回字符串左边的字符
len() 返回字符串的长度
lower() 转换小写
right() 返回字符串右边的字符
soundex() 返回字符串的SOUNDEX值
upper() 转换大写

select n_content from nrc_news where DATEPART(YY,n_publishtime)=2015;
select n_content from nrc_news where DATEPART(YYYY,n_publishtime)=2015;
数值处理函数:
abs() 返回一个数的绝对值
cos() 返回一个角度的余弦
exp() 返回一个数的指数值
pi() 返回圆周率
sin() 返回一个数的正弦
sqrt() 返回一个数的平方根
tan() 返回一个数的正切

select ABS(n_id) from nrc_news;
select cos(n_id) from nrc_news;
select exp(n_id) from nrc_news;
select pi() from nrc_news;
select SIN(n_id) from nrc_news;
select sqrt(n_id) from nrc_news;
select tan(n_id) from nrc_news;

汇总数据
AVG() 返回某列的平均值
COUNT() 返回某列的行数
MAX() 返回某列的最大值
MIN() 返回某列的最小值
SUM() 返回某列之和
select avg(t_id) from nrc_news;
select count(t_id) from nrc_news;
select max(t_id) from nrc_news;
select min(t_id) from nrc_news;
select sum(t_id) from nrc_news;
注:
avg()只能用来确定特定数值列的平均值,而且列明必须作为函数参数给出,如果要获得多个列的平均值,必须用多个avg()
avg()函数忽略列值为NULL的行

select count(*) from nrc_news where t_id=10;

数据分组
select t_id,count(*)as number from nrc_news group by t_id;
注解:
上面的SELECT语句制定了两个列,t_id和number(计算字段).group by 子句会指示数据库按t_id排序并分组数据.这样会对每个t_id而不是整个表计算number
这样输出的就是每个t_id所对应的行的数量

select t_id,count(*)as number from nrc_news group by t_id having COUNT(*)>=2;
注:
HAVING 和 WHERE 的差别
where是在数据分组前进行过滤,having是在数据分组后进行过滤
共同使用的时候,where排除的值不包括在分组中,会影响having的计算

使用子查询
select * from nrc_news where t_id in(1,2);
select t_id from nrc_news where n_content like '%就%';

select * from nrc_news where t_id in(select t_id from nrc_news where n_content like '%就%');
注:
作为子查询的select语句只能查询单个列,企图检索多个列将返回错误
select r_id,r_content,n_id,(select t_id from nrc_news where nrc_news.n_id=nrc_review.n_id)as orders from nrc_review ;
select n_id,n_title,t_id,(select t_memo from nrc_type where nrc_type.t_id=nrc_news.t_id)as t_memo from nrc_news
上述子查询为重点内容。重点记忆。
select top 10 n_id as id,
(select n_title from nrc_news where nrc_news.n_id=nrc_review.n_id)as title,
(select n_content from nrc_news where nrc_news.n_id=nrc_review.n_id)as content,
(select t_id from nrc_news where nrc_news.n_id=nrc_review.n_id)as t_id,
(select n_publishtime from nrc_news where nrc_news.n_id=nrc_review.n_id)as publishtime,
COUNT(*)as number from nrc_review group by n_id order by number desc,id;

sql次级语句的更多相关文章

  1. [转]MySQL 最基本的SQL语法/语句

    MySQL 最基本的SQL语法/语句,使用mysql的朋友可以参考下.   DDL-数据定义语言(Create,Alter,Drop,DECLARE) DML-数据操纵语言(Select,Delete ...

  2. SQL入门语句之ORDER BY 和GROUP BY

    一.SQL入门语句之ORDER BY ORDER BY 是用来基于一个或多个列按升序或降序顺序排列数据 1.从数据库表获取全部数据按字段A的升序排列 select *from table_name o ...

  3. SQL入门语句之LIKE、GLOB和LIMIT

    一.SQL入门语句之LIKE LIKE用来匹配通配符指定模式的文本值.如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1.这里有两个通配符与 LIKE 运算符一起使用,百 ...

  4. SQL入门语句之SELECT和WHERE

    一.SQL入门语句之SELECT SELECT语句用于从数据库表中获取数据,结果表的形式返回数据.这些结果表也被称为结果集 1.从数据库表中取部分字段 select 字段A,字段B from tabl ...

  5. SQL入门语句之INSERT、UPDATE和DELETE

    一.SQL入门语句之INSERT insert语句的功能是向数据库的某个表中插入一个新的数据行 1.根据对应的字段插入相对应的值 insert into table_name(字段A, 字段B, 字段 ...

  6. 快速将一个表的数据生成SQL插入语句

    将一个表中的数据生成SQL插入语句,方便系统快速初始化,在数据库中执行创建以下过程就可以了. ) Drop Procedure GenerateData go CREATE PROCEDURE Gen ...

  7. sql查询语句如何解析成分页查询?

    我们公司主要mysql存储数据,因此也封装了比较好用mysql通用方法,然后,我们做大量接口,在处理分页查询接口,没有很好分查询方法.sql查询 语句如何解析成“分页查询”和“总统计”两条语句.可能, ...

  8. 规则引擎集成接口(四)SQL执行语句

    SQL执行语句 右键点击数据库连接文件“hr”—“添加SQL执行语句”,如下图: 弹出窗体,如下图: 将显示名称改为“部门名称”,返回至类型设置为“string”,在编写sql语句,如下图: 点击确定 ...

  9. SQL SELECT 语句

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

随机推荐

  1. Codeforces Round #452 (Div. 2) 899E E. Segments Removal

    题 OvO http://codeforces.com/contest/899/problem/E Codeforces Round #452 (Div. 2) - e 899E 解 用两个并查集(记 ...

  2. 图像的padding操作

    为了完成卷积后图像大小不变,原始图像需要进行边界填充 copyMakeBorder(src,dst,top,bottom,left,right,bordertype,value); bordertyp ...

  3. Appium Python核心API

    adb命令模拟按键事件 :http://blog.sina.com.cn/s/blog_68f262210102vc1b.html

  4. learning armbian steps(7) ----- armbian 源码分析(二)

    从compile.sh开始入手: SRC="$(dirname "$(realpath "${BASH_SOURCE}")")" # fal ...

  5. tqdm如何在pandas里面使用

    原文: https://segmentfault.com/a/1190000016059726 当然,首先我们得载入模块,在notebook中使用tqdm带的基于Js显示的进度条前,请务必检查是否安装 ...

  6. OpenGL 开发环境配置:Visual Studio 2017 + GLFW + GLEW

    Step1:Visual Studio 2017 Why 开发环境,后面编译GLFW 和 GLEW也要用 How 这里使用的是Visual Studio 2017的 Community 版本,直接官网 ...

  7. python并发——信号量

    信号量通常用于保护数量有限的资源,例如数据库服务器.在资源数量固定的任何情况下,都应该使用有界信号量.在生成任何工作线程前,应该在主线程中初始化信号量. 工作线程生成后,当需要连接服务器时,这些线程将 ...

  8. Imagetragick 命令执行漏洞(CVE-2016–3714)

    Imagetragick介绍: ImageMagick是一款使用量很广的图片处理程序,很多厂商都调用了这个程序进行图片处理,包括图片的伸缩.切割.水印.格式转换等等.但近来有研究者发现,当用户传入一个 ...

  9. js优先队列的定义和使用

    //队列,先入先出,FIFO function Queue() { this.items = []; } Queue.prototype = { constructor: Queue, enqueue ...

  10. Difference between C# compiler version and language version

    Difference between C# compiler version and language version     As nobody gives a good enough answer ...