zoukankan      html  css  js  c++  java
  • SQLite常用SQL语句

     

    创建表格

    sql="CREATE TABLE IF NOT EXISTS MusicList (id integer primary key AutoIncrement,name varchar(20),path varchar(20))";

    查询表格

    查看表结构
    desc <table>;

    查看所有数据
    select * from <table>;

    查看指定的列数据
    select , from <table>;

    查看非重复数据
    select distinct , from <table>;

    复制数据
    insert into users(_id,username,password) select * from users;

    首字母为S的数据
    select username from users where username like 'S%' ;

    第三个字母为S的数据
    select username from users where username like '__S%' ;

    查询001,220,230的数据
    select * from users where _id in(001,220,230);

    顺序查询
    select * from users where _id in(001,220,230);

    反顺序查询
    select * from user order by _id desc;

    分页功能

    获取数据行总数
    select count(word) as number from <table>;

    分页查询
    select , from <table> order by word limit 100 offset 200;

    SQLite内建函数表

    算术函数

    • abs(X) 返回给定数字表达式的绝对值。
    • max(X,Y[,...]) 返回表达式的最大值。
    • min(X,Y[,...]) 返回表达式的最小值。
    • random(*)返回随机数。
    • round(X[,Y])返回数字表达式并四舍五入为指定的长度或精度。

    字符处理函数

    • length(X) 返回给定字符串表达式的字符个数。
    • lower(X)将大写字符数据转换为小写字符数据后返回字符表达式。
    • upper(X)返回将小写字符数据转换为大写的字符表达式。
    • substr(X,Y,Z)返回表达式的一部分。
    • randstr()
    • quote(A)
    • like(A,B)确定给定的字符串是否与指定的模式匹配。
    • glob(A,B)

    条件判断函数

    • coalesce(X,Y[,...])
    • ifnull(X,Y)
    • nullif(X,Y)

    集合函数

    • avg(X)返回组中值的平均值。
    • count(X)返回组中项目的数量。
    • max(X)返回组中值的最大值。
    • min(X)返回组中值的最小值。
    • sum(X)返回表达式中所有值的和。

    其他函数

    • typeof(X)返回数据的类型。
    • last_insert_rowid()返回最后插入的数据的ID。
    • sqlite_version(*)返回SQLite的版本。
    • change_count()返回受上一语句影响的行数。
    • last_statement_change_count()
  • 相关阅读:
    event.preventDefault()
    laravel 授权使用gate门类
    Redis在Laravel项目中的应用实例详解
    Laravel实现找回密码及密码重置的例子
    2016-2017中国房地产走势大数据报告亮相
    特许金融分析师 (CFA) 持证人现在一般在做什么工作?职业分布是怎样的?
    工作中最常用的Excel函数公式大全
    151项国家职业资格目录清单公示
    中国 世界十大投资风云人物,谁是自己的指路明灯!
    世界十大投资风云人物,你知道几个?
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/5644300.html
Copyright © 2011-2022 走看看