• 查询语句格式


     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)

  • 相关阅读:
    Pytorch-情感分类实战(基于LSTM,调用torchtext)
    Pytorch-LSTM
    Pytorch-时间序列预测
    Pytorch-RNN
    SQLServer -------- 包含(charindex)
    .NET ------ 树形菜单,点击单选按钮触发相应事件
    电子秤Xk3190-A12+E 称重方式的设置方法
    串口调试工具与com口编程
    .NET ------ Repeater 遍历数据显示在页面上
    .NET ------ 将弹窗内增加选项卡
  • 原文地址:https://www.cnblogs.com/sunshine-habit/p/4864807.html
Copyright © 2020-2023  润新知