索引

Sorting Retrieved Data

mysql> SELECT *
-> FROM manga
-> ORDER BY manga_name;
+----------+-----------------------+-------------------+--------------+
| manga_id | manga_name | manga_discription | manga_status |
+----------+-----------------------+-------------------+--------------+
| 1005 | 2asdasds | dasd | 0 |
| 1006 | 3dasdas) | 别出心裁 | 0 |
| 1007 | 4444444444 | 3333 | 0 |
| 1004 | dasda | 23123 | 0 |
mysql> SELECT *
-> FROM manga
-> ORDER BY manga_name, manga_discription; # 先按 name 排,然后按 discription
+----------+-----------------------+-------------------+--------------+
| manga_id | manga_name | manga_discription | manga_status |
+----------+-----------------------+-------------------+--------------+
| 1005 | 2asdasds | dasd | 0 |
| 1006 | 3dasdas) | 别出心裁 | 0 |
| 1007 | 4444444444 | 3333 | 0 |
| 1004 | dasda | 23123 | 0 |
mysql> SELECT *
-> FROM manga
-> ORDER BY manga_name DESC, manga_discription; # 第一次排是降序(Z~A),第二次(内部排)还是正常序(A~Z)
+----------+-----------------------+-------------------+--------------+
| manga_id | manga_name | manga_discription | manga_status |
+----------+-----------------------+-------------------+--------------+
| 1000 | 至不死的你 | 以为是哲学 | 0 |
| 1001 | 烙印勇士 | 好看到哭 | 0 |
| 1002 | 幸福(happiness) | 别出心裁 | 0 |
| 1003 | 东京食尸鬼 | 美食动漫 | 0 |

Using a combination of ORDER BY and LIMIT, it is possible to find the highest or lowest value in a column. The following example demonstrates how to find the value of the most expensive item:

SELECT prod_price
FROM products
ORDER BY prod_price DESC
LIMIT 1;

Position of ORDER BY Clause When specifying an ORDER BY clause, be sure that it is after the FROM clause. If LIMIT is used, it must come after ORDER BY. Using clauses out of order will generate an error message.

SQL Versus Application Filtering

Data can also be filtered at the application level. To do this, the SQL SELECT statement retrieves more data than is actually required for the client application, and the client code loops through the returned data to extract just the needed rows.

As a rule, this practice is strongly discouraged. Databases are optimized to perform filtering quickly and efficiently. Making the client application (or development language) do the database's job dramatically impacts application performance and creates applications that cannot scale properly. In addition, if data is filtered at the client, the server has to send unneeded data across the network connections, resulting in a waste of network bandwidth resources.

The WHERE Clause Operators

mysql> SELECT manga_id, manga_name
-> FROM manga
-> WHERE manga_name='big';
+----------+------------+
| manga_id | manga_name |
+----------+------------+
| 1008 | BIG |
| 1009 | big |
| 1010 | Big |
| 1011 | BiG |
+----------+------------+
4 rows in set (0.00 sec)

By default, MySQL is not case sensitive when performing matches, and so fuses and Fuses matched.

不过需要注意的是 LIKE + '通配符语句' 是 case-sensitive (大小写敏感的)

/

mysql> SELECT manga_id, manga_name
-> FROM manga
-> WHERE manga_id BETWEEN 1005 AND 1007;
+----------+------------+
| manga_id | manga_name |
+----------+------------+
| 1005 | 2asdasds |
| 1006 | 3dasdas) |
| 1007 | 4444444444 |
+----------+------------+
3 rows in set (0.00 sec)

/

mysql> SELECT manga_id, manga_name
-> FROM manga
-> WHERE manga_name IS NULL;
Empty set (0.00 sec)

网上有建议说 尽可能设定默认值而不是用 NULL

MySQL Crash Course #03# Chapter 5. 6 排序. BETWEEN. IS NULL的更多相关文章

  1. MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables

    之前 manipulate 表里的数据,现在则是 manipulate 表本身. INDEX 创建多列构成的主键 自动增长的规定 查看上一次插入的自增 id 尽量用默认值替代 NULL 外键不可以跨引 ...

  2. MySQL Crash Course #11# Chapter 20. Updating and Deleting Data

    INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...

  3. MySQL Crash Course #10# Chapter 19. Inserting Data

    INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Singl ...

  4. MySQL Crash Course #06# Chapter 13. 14 GROUP BY. 子查询

    索引 理解 GROUP BY 过滤数据 vs. 过滤分组 GROUP BY 与 ORDER BY 之不成文的规定 子查询 vs. 联表查询 相关子查询和不相关子查询. 增量构造复杂查询 Always ...

  5. MySQL Crash Course #04# Chapter 7. 8 AND. OR. IN. NOT. LIKE

    索引 AND. OR 运算顺序 IN Operator VS. OR NOT 在 MySQL 中的表现 LIKE 之注意事项 运用通配符的技巧 Understanding Order of Evalu ...

  6. MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance

    终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...

  7. MySQL Crash Course #20# Chapter 28. Managing Security

    限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性. 详细文档:https://dev.mysql.com/doc/refman/8.0/en/user-account-manag ...

  8. MySQL Crash Course #19# Chapter 27. Globalization and Localization

    Globalization and Localization When discussing multiple languages and characters sets, you will run ...

  9. MySQL Crash Course #18# Chapter 26. Managing Transaction Processing

    InnoDB 支持 transaction ,MyISAM 不支持. 索引: Changing the Default Commit Behavior SAVEPOINT 与 ROLLBACK TO ...

随机推荐

  1. 8.17 一个博客demo

    2018-8-17 18:13:27 明天周末准备整理一下看看我的博客!!! 说一下思路 1.先搭建框架 1.1 大体分成两块div 左右两部分 <div class="left&qu ...

  2. 计蒜客 30999 - Sum - [找规律+线性筛][2018ICPC南京网络预赛J题]

    题目链接:https://nanti.jisuanke.com/t/30999 样例输入258 样例输出814 题意: squarefree数是指不含有完全平方数( 1 除外)因子的数, 现在一个数字 ...

  3. Python 文件内容读取

    # 读取数据的函数 def readData(filename): with open(filename, 'r') as f: data = f.read().lower() data = list ...

  4. Windows server 2016 安装及ORACLE 12C 安装

    首先创建虚拟机,选择windows server 2016 启动虚拟机,进入安装界面,语言默认中文,选择下一步 选择标准安装(桌面) 选择接受条款 选择自定义安装 进行分区,如下图所示 进行安装 设定 ...

  5. 洛谷P2577 [ZJOI2005]午餐 dp

    正解:序列dp 解题报告: 传送门! 这题首先要想到一个显然的贪心:每个窗口的排队顺序都是按照吃饭时间从大到小排序的 证明如下: 这种贪心通常都是用微扰法,这题也不例外 现在假如已经确定了每个窗口有哪 ...

  6. django源码笔记-【2】(转)

    add by zhj: 在原文的基础上有修改 原文:http://www.cnblogs.com/gaott/archive/2012/02/28/2371238.html 上一期完理解了WSGI处理 ...

  7. 格式化NameNode

    $cd /app/hadoop/hadoop-2.2.0/ $./bin/hdfs namenode -format

  8. DeepMind提出空间语言集成模型SLIM,有效编码自然语言的空间关系

    前不久,DeepMind 提出生成查询网络 GQN,具备从 2D 画面到 3D 空间的转换能力.近日.DeepMind 基于 GQN 提出一种新模型.可以捕捉空间关系的语义(如 behind.left ...

  9. Spark SQL入门用法与原理分析

    Spark SQL是为了让开发人员摆脱自己编写RDD等原生Spark代码而产生的,开发人员只需要写一句SQL语句或者调用API,就能生成(翻译成)对应的SparkJob代码并去执行,开发变得更简洁 注 ...

  10. JSP表单提交与接收

    JSP表单提交与接收 在Myeclipse中新建web project,在webroot中新建userRegist1.jsp,代码如下 <%@ page contentType="te ...