zoukankan      html  css  js  c++  java
  • sqlite 的基本使用3

    AND 运算符和OR运算符

    这两个运算符一般被称为连接运算符,用来缩小sqlite所选的数据

    AND 运算符是当所有的条件都为真时,表达式才为真

    sqlite> select * from student where id = 2 and name = "bb";
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    sqlite> 

    OR运算符是当其中一个条件为真时,表达式才为真

    sqlite> select * from student where id = 5 or name = "bb";
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    4           bb          45        
    sqlite> 

    update语句用于修改表中的记录,可以用于where 语句选择记录行,否则所有的记录都会被修改

    sqlite> update student set age = 22 where id = 3;
    sqlite> select * from student;
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    3           cc          22        
    1           abcdef      56        
    4           bb          45        
    sqlite> 

    delete 语句用于删除数据库中的记录一般和where 一起使用

    sqlite> delete from student where id = 4;
    sqlite> select * from student;
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    3           cc          22        
    1           abcdef      56        
    sqlite> 

    SQLite 的 LIKE 运算符是用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1。这里有两个通配符与 LIKE 运算符一起使用:

    • 百分号 (%)

    • 下划线 (_)

    百分号(%)代表零个、一个或多个数字或字符。下划线(_)代表一个单一的数字或字符。这些符号可以被组合使用。

    sqlite> select * from student where name like "%cd%";
    id          name        age       
    ----------  ----------  ----------
    1           abcdef      56        
    sqlite> select * from student where name like "b_";
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    sqlite> 

    SQLite 的 GLOB 运算符是用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,GLOB 运算符将返回真(true),也就是 1。与 LIKE 运算符不同的是,GLOB 是大小写敏感的,对于下面的通配符,它遵循 UNIX 的语法。

    • 星号 (*)

    • 问号 (?)

    星号(*)代表零个、一个或多个数字或字符。问号(?)代表一个单一的数字或字符。这些符号可以被组合使用。

    sqlite> select * from student where name glob "*cd*";
    id          name        age       
    ----------  ----------  ----------
    1           abcdef      56        
    sqlite> select * from student where name glob "b?";
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    sqlite> 

    SQLite 的 LIMIT 子句用于限制由 SELECT 语句返回的数据数量,有时候也与offset一起连用

    sqlite> select * from student limit 2;
    id          name        age       
    ----------  ----------  ----------
    2           bb          12        
    3           cc          22        
    sqlite> select * from student limit 2 offset 1;;
    id          name        age       
    ----------  ----------  ----------
    3           cc          22        
    1           abcdef      56        
    sqlite> 
  • 相关阅读:
    AfxMessageBox详细使用说明
    动态规划: 求一个一维整数数组的最大子序列和
    常见HTTP状态码
    PHP 基础系列(三) 【转】PHP 函数实现原理及性能分析
    empty() isset() isnull() 比较
    isset() 与 array_key_exists() 比较
    PHP基础系列(二) PHP数组相关的函数分类整理
    PHP基础系列(一) PHP字符串相关的函数分类整理
    linux df 命令
    grep 同时满足多个关键字和满足任意关键字
  • 原文地址:https://www.cnblogs.com/techdreaming/p/5603638.html
Copyright © 2011-2022 走看看