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;

另外+,-,*,/都可以使用

最新文章

  1. mysql 实现 start with
  2. javascript实现简单的轮播图片
  3. SQL匹配顺序
  4. 网站标题ico那些事
  5. window7部署solr 4.7
  6. Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp
  7. 第二百五十六天 how can I 坚持
  8. 20141015--for语句1
  9. angular中的orderBy过滤器使用
  10. 微信开发之开发环境搭建( visual studio 2015we + IIS express + ngrok)
  11. 谈一下spring 的理解
  12. aspnetpager分页,不使用存储过程
  13. ORA-12514(TNS:监听程序当前无法识别...)
  14. Web Design 再生:UX Design
  15. jquery getScript动态加载JS方法改进详解[转载]
  16. POJ 2601
  17. VS2010/2013 运行是很卡的加速方案
  18. TensorFlow分布式实践
  19. Android Intent Service
  20. 关于C++静态成员函数访问非静态成员变量的问题

热门文章

  1. BZOJ 2982 combination 脑子+组合数学
  2. 图的最小生成树(java实现)
  3. Codevs 2482 宝库通道 2007年省队选拔赛安徽
  4. Django基础之命名URL和URL反向解析
  5. Java 显示锁 之 重入锁 ReentrantLock(七)
  6. Guava中Lists.partition(List, size) 方法懒划分/懒分区
  7. Amdahl定律和可伸缩性
  8. JWT加密解密
  9. Linux Centos安装宝塔面板教程
  10. linux下如何进入chroot环境?