sql普通语句
select DISTINCT t_id from nrc_news
DISTINCT不会输出相同的值
select top 5 * from nrc_news;
检索前五行
select * from nrc_news order by t_id;
通过子列t_id排序
注:指定一条order by子句时,应该保证它是select语句最后一条子句,如果不是,会报错
select * from nrc_news order by t_id,n_publishtime;
select * from nrc_news order by 4,5;
使用两条规则进行排序
select * from nrc_news order by t_id DESC;
select * from nrc_news order by t_id ASC;
降序和升序
select * from nrc_news order by t_id DESC,n_publishtime;
最大的t_id在前面然后按时间排序
select * from nrc_news where t_id=10;
过滤条件t_id=10
where操作符
= 等于
<> 不等于
!= 不等于
< 小于
<= 小于等于
!< 不小于
> 大于
>= 大于等于
!> 不大于
BETWEEN 在指定的两个值之间
IS NULL 为NULL值
例:
select * from nrc_news where t_id <> 10;
!=和<>通常可以互换。但是,并非所有DBMS都支持这两种不等于操作符。例如Microsoft Access支持<>不支持!=
select * from nrc_news where t_id between 3 and 9;
select * from nrc_news where t_id is null;
select * from nrc_news where t_id between 3 and 9 and n_id<> 3;
select * from nrc_news where t_id between 3 and 9 or n_id<> 3;
SQL语句中
and的处理是优先于or的处理的
select * from nrc_news where n_id>8 or n_id<2 and t_id<10;
select * from nrc_news where (n_id>8 or n_id<2) and t_id<10;
select * from nrc_news where t_id IN (1,2,3,4);
等于
select * from nrc_news where t_id=1 or t_id=2 or t_id=3 or t_id=4;
NOT可以否定后续的判断
select * from nrc_news where not t_id=1;
使用通配符进行判断:
select * from nrc_news where n_content like '%就%';
select * from nrc_news where n_content like '小%';
select * from nrc_news where n_content like '%了';
注:请注意NUll
where t_id like '%'不会匹配为NULL的行
select * from nrc_news where n_title like '梦_';
select * from nrc_news where n_title like '[梦喷]%';
select * from nrc_news where n_title like '[^梦喷]%';//除了梦和喷之外所有的开头
拼接字段:
select n_title+'('+n_content+')' from nrc_news ;
注:TRIM函数
大多数DBMS都支持RTRIM()(去掉字符串右边的空格),LTRIM()(去掉字符串左边的空格),TRIM()(去掉字符串两边的空格)函数
select n_id,n_title,n_content,n_id*t_id as number from nrc_news order by number;
另外+,-,*,/都可以使用
sql普通语句的更多相关文章
- [转]MySQL 最基本的SQL语法/语句
MySQL 最基本的SQL语法/语句,使用mysql的朋友可以参考下. DDL-数据定义语言(Create,Alter,Drop,DECLARE) DML-数据操纵语言(Select,Delete ...
- SQL入门语句之ORDER BY 和GROUP BY
一.SQL入门语句之ORDER BY ORDER BY 是用来基于一个或多个列按升序或降序顺序排列数据 1.从数据库表获取全部数据按字段A的升序排列 select *from table_name o ...
- SQL入门语句之LIKE、GLOB和LIMIT
一.SQL入门语句之LIKE LIKE用来匹配通配符指定模式的文本值.如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1.这里有两个通配符与 LIKE 运算符一起使用,百 ...
- SQL入门语句之SELECT和WHERE
一.SQL入门语句之SELECT SELECT语句用于从数据库表中获取数据,结果表的形式返回数据.这些结果表也被称为结果集 1.从数据库表中取部分字段 select 字段A,字段B from tabl ...
- SQL入门语句之INSERT、UPDATE和DELETE
一.SQL入门语句之INSERT insert语句的功能是向数据库的某个表中插入一个新的数据行 1.根据对应的字段插入相对应的值 insert into table_name(字段A, 字段B, 字段 ...
- 快速将一个表的数据生成SQL插入语句
将一个表中的数据生成SQL插入语句,方便系统快速初始化,在数据库中执行创建以下过程就可以了. ) Drop Procedure GenerateData go CREATE PROCEDURE Gen ...
- sql查询语句如何解析成分页查询?
我们公司主要mysql存储数据,因此也封装了比较好用mysql通用方法,然后,我们做大量接口,在处理分页查询接口,没有很好分查询方法.sql查询 语句如何解析成“分页查询”和“总统计”两条语句.可能, ...
- 规则引擎集成接口(四)SQL执行语句
SQL执行语句 右键点击数据库连接文件“hr”—“添加SQL执行语句”,如下图: 弹出窗体,如下图: 将显示名称改为“部门名称”,返回至类型设置为“string”,在编写sql语句,如下图: 点击确定 ...
- SQL SELECT 语句
本章讲解 SELECT 和 SELECT * 语句. SQL SELECT 语句 SELECT 语句用于从表中选取数据. 结果被存储在一个结果表中(称为结果集). SQL SELECT 语法 SE ...
- 画图解释SQL联合语句
画图解释SQL联合语句 http://blog.jobbole.com/40443/ 我认为 Ligaya Turmelle 的关于SQL联合(join)语句的帖子对于新手开发者来说是份很好的材料.S ...
随机推荐
- HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5
看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...
- linux系统相关文件和操作
查看内核: uname -r [root@server0 ~]# uname -r -.el7.x86_64 [root@server0 ~]# 查看版本: cat /etc/redhat-rele ...
- 爬虫代理池源代码测试-Python3WebSpider
元类属性的使用 来源: https://github.com/Python3WebSpider/ProxyPool/blob/master/proxypool/crawler.py 主要关于元类的使用 ...
- Luogu P2114_[NOI2014]起床困难综合症 贪心
思路:按位贪心. 提交:1次 题解: 可以先处理出对于全$0$串和全$1$串最后每一位的结果.(每一位 从 $0$ $or$ $1$ 变成 $0$ $or$ $1$) 对于每一位,若不能变成$1$,则 ...
- PHP mysqli_get_client_info() 函数
定义和用法 mysqli_get_client_info() 函数返回 MySQL 客户端库版本. <?php echo mysqli_get_client_info(); ?>
- @Test 测试
package com.自定义.mall.admin.system; import java.util.List; import java.util.Map; import javax.annotat ...
- Python GUI编程(Tkinter)(一)
tk官网的教程学习: https://tkdocs.com/tutorial/firstexample.html 学习blog: https://www.cnblogs.com/aland-1415/ ...
- bat 通过命令以管理员方式运行程序
@echo off mode con lines= cols= % mshta vbscript:CreateObject()(window.close)&&exit cd /d &q ...
- nodejs的npm命令无反应的解决方案
这二天用npm下载模块的时候输入npm命令完全无反应,不是加载的那种状态而是下标不停地在哪里闪...之后找解决方案,说要删除npmrc文件.强调:不是nodejs安装目录npm模块下的那个npmrc文 ...
- webstorm设置babel,使用es6
原文链接:https://blog.csdn.net/peade/article/details/76522177 网上有很多关于如何设置babel的.我学习着设置,但总差那么几步,没能满足我的需求. ...