mysql select语句操作实例

前端技术 2023/09/10 MYSQL

Select的语法

复制代码 代码如下:

SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr, ...
    [INTO OUTFILE \'file_name\' export_options
      | INTO DUMPFILE \'file_name\']
    [FROM table_references
    [WHERE where_definition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_definition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC] , ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [FOR UPDATE | LOCK IN SHARE MODE]]

SELECT用于恢复从一个或多个表中选择的行,并可以加入UNION语句和子查询。

每个select_expr都指示一个您想要恢复的列, table_references指示行从哪个表或哪些表中被恢复。

简单查询

复制代码 代码如下:

SELECT columna columnb FROM mytable;

ORDER BY查询

复制代码 代码如下:

SELECT college, region, seed FROM tournament  ORDER BY region, seed;
SELECT college, region AS r, seed AS s FROM tournament ORDER BY r, s;
SELECT college, region, seed FROM tournament  ORDER BY 2, 3;

--要以相反的顺序进行分类,应把DESC(降序)关键字添加到ORDER BY子句中的列名称中。默认值为升序;该值可以使用ASC关键词明确地指定。
SELECT a, COUNT(b) FROM test_table ORDER BY a DESC;

本文地址:https://www.stayed.cn/item/26386

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。