sqlite常用的函数

  1. substr(x, y) 获取截取后的字符串substr,
    例如: 表data_info 中包含[2DCode] ,[Rand] 两个字段,截取[2Dcode]部分字符串—
    select substr([2DCode],37) ,[Rand]
    from data_info
  2. instr(x,y)返回某个字符在字符串中的位置instr,可与substr(x,y)连用。
    例如:
    select substr([2DCode], instr([2DCode],’=’)+1) ,[Rand] from data_info
  3. distinct 关键字 distinct
  4. count( distinct column名 ) 聚合函数与distinct 连用count(distinct) ,在任何只有一个参数的聚合函数中,可以在这个参数前使用distinct 关键字。例如:获取表suitData—_info 表中的去重后的boxUII的数量—select count(distinct [boxUII]) from suitData_info
  5. 查询db文件中所有表的索引名

SELECT DISTINCT m.name || ‘.’ || ii.name AS ‘indexed-columns’
FROM sqlite_master AS m,
pragma_index_list(m.name) AS il,
pragma_index_info(il.name) AS ii
WHERE m.type=‘table’
ORDER BY 1;
6. select 数据表中的重复数据:having
select 字段 from 表 where 字段 in (Select 字段 from 表
where 条件
Group by 字段
Having count(字段)>1)
例如: select bottle_id from bottle_in_box
where bottle_id in (Select bottle_id from bottle_in_box
where pro_bill=‘E20190812309’
Group by bottle_id
Having count(bottle_id )>1);
或者是:
select column1 from table1 where column1
in (Select column1 from table1
where 条件
Group by column1
Having count(column1)>1)
7. 查询两张表:使用 as 关键字
as
select b.bill,(A.numc*B.spec) as result from
(select count(distinct bottle_id) as numc from bottle_in_box where pro_bill=‘E2019081923’ ) A,
(
select p.product_bill as bill, p.PRODUCT_SPEC as spec from plan_history p where p.product_bill=‘E2019081923’
)B

  1. IN 操作符允许我们在 WHERE 子句中规定多个值
    例如: SELECT * FROM Persons
    WHERE LastName IN (‘Adams’,‘Carter’);
    批量更新时,也可以使用
    update table1 set column1 =0 where column2 in (values1,values2,…) ;

注: 可下载SQLite.Net文件查阅,点击sqlite.helper下载

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值