zoukankan      html  css  js  c++  java
  • 查询语句格式

     1 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [HIGH_PRIORITY]  
     2 [DISTINCT | DISTINCTROW | ALL]  
     3 select_expression,...  
     4 [INTO {OUTFILE | DUMPFILE} 'file_name' export_options]  
     5 [FROM table_references  
     6 [WHERE where_definition]  
     7 [GROUP BY col_name,...]  
     8 [HAVING where_definition]  
     9 [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...]  
    10 [LIMIT [offset,] rows]  
    11 [PROCEDURE procedure_name] ] 

    1.查询所有数据:

    select * from table;

    2.查询行:

    select * from table where (字段名1=‘xx’ and 字段名2!='xx' )  or 字段名3>100;

    3.查询列:

    select 字段1,字段2,字段3... from table;

    4.查询排序行:

    正序:select * from table order by 字段名1,字段名2;(可按多字段优先级排序)

    倒序:select * from table order by 字段名1,字段名2 desc;(可按多字段优先级排序)

    5.日期计算:(日期函数)

     1 mysql> select * from user;
     2 +----+------+----------+------+------+---------------------+---------------------+
     4 | Id | name | nikename | sex  | age  | birth_date          | goodbye_date 5  |
     6 +----+------+----------+------+------+---------------------+---------------------+
     8 |  1 | yql  | sunshine |    1 |   28 | 1988-10-20 10:00:00 | NULL 9  |
    10 |  2 | Sam  | Sam      |    0 |   25 | 1989-10-20 10:00:00 | 2005-03-20 10:00:0011  |
    12 +----+------+----------+------+------+---------------------+---------------------+
     1 插入一条记录:
     2 mysql> insert into user (id,name,nikename,sex,age,birth_date) values(1,'yql','sunshine',1,28,'1989-10-20 10:00:00')
     3 查看计算结果:to_days(now())天数
     4 mysql> select  name,(to_days(now())-to_days(birth_date))/365 as age1 from user;
     5 +------+---------+
     6 | name | age1    |
     7 +------+---------+
     8 | yql  | 26.9863 |
     9 +------+---------+
    10 1 row in set (0.06 sec)

  • 相关阅读:
    codevs 1031 质数环
    codevs 1005 生日礼物
    codevs 1004 四子连棋
    codevs 2292 图灵机游戏
    1439 统计素数个数
    1675 大质数 2
    codevs 1462 素数和
    [NOIp2012提高组]借教室
    [NOIp2007提高组]矩阵取数游戏
    [TJOI2017]城市
  • 原文地址:https://www.cnblogs.com/sunshine-habit/p/4864807.html
Copyright © 2011-2022 走看看