• MySQL Crash Course #02# Chapter 3. 4 通配符. 分页


    索引

    Learning About Databases and Tables 

    Learning More About SHOW In the mysql command-line utility, execute command HELP SHOW; to display a list of allowed SHOW statements.

    查看表结构.创建表信息

    DESC table_name;
    SHOW CREATE TABLE table_name;

    The SELECT Statement

    To use SELECT to retrieve table data you must, at a minimum, specify two pieces of information what you want to select, and from where you want to select it.

    Presentation of Data

    SQL statements typically return raw, unformatted data. Data formatting is a presentation issue, not a retrieval issue. Therefore, presentation (for example, alignment and displaying the price values as currency amounts with the currency symbol and commas) is typically specified in the application that displays the data. Actual raw retrieved data (without application-provided formatting) is rarely displayed as is.

    Using Wildcards 

    As a rule, you are better off not using the * wildcard unless you really do need every column in the table. Even though use of wildcards might save you the time and effort needed to list the desired columns explicitly, retrieving unnecessary columns usually slows down the performance of your retrieval and your application.

    Retrieving Distinct Rows

    在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。

    SELECT DISTINCT vend_id tells MySQL to only return distinct (unique) vend_id rows, and so only 4 rows are returned, as seen in the following output. If used, the DISTINCT keyword must be placed directly in front of the column names.

    select distinct name, id from A

     更多详细内容可以参阅 MySQL中distinct的使用方法

    Limiting Results

    mysql> SELECT manga_id, manga_name
        -> FROM manga
        -> LIMIT 3;
    +----------+-----------------------+
    | manga_id | manga_name            |
    +----------+-----------------------+
    |     1000 | 至不死的你            |
    |     1001 | 烙印勇士              |
    |     1002 | 幸福(happiness)     |
    +----------+-----------------------+
    mysql> SELECT manga_id, manga_name
        -> FROM manga
        -> LIMIT 3,3;
    +----------+-----------------+
    | manga_id | manga_name      |
    +----------+-----------------+
    |     1003 | 东京食尸鬼      |
    |     1004 | dasda           |
    |     1005 | 2asdasds        |
    +----------+-----------------+

    返回的行是第 4, 5 ,6 行。

    When There Aren't Enough Rows The number of rows to retrieve specified in LIMIT is the maximum number to retrieve. If there aren't enough rows (for example, you specified LIMIT 10,5, but there were only 13 rows), MySQL returns as many as it can.

    Using Fully Qualified Table Names

    mysql> SELECT manga.manga_id
        -> FROM mangast.manga;
    +----------+
    | manga_id |
    +----------+
    |     1000 |
    |     1001 |

    在某些情况下应用全名是必要的。

    
    
    
  • 相关阅读:
    monkeyrunner之夜神模拟器的安装与使用(二)
    monkeyrunner之安卓开发环境搭建(一)
    MySQL 返回未包含在group by中的列
    MySQL数据库初体验
    MongoDB安装
    关于数据库你必须知道的事~
    PostgreSQL中的MVCC 事务隔离
    深入浅出MySQL之索引为什么要下推?
    Java集合篇:Map集合的几种遍历方式及性能测试
    Oracle11g:数据库恢复总结
  • 原文地址:https://www.cnblogs.com/xkxf/p/8653183.html
Copyright © 2020-2023  润新知