sqlite查询语句
搜索距现在六个月前的月份第一天日期:
SELECT date('now','start of month','-6 month','0 day');
搜索距现在六个月前的日期:
SELECT date('now','-6 month','0 day');
case when 用法:
栗子:
select case when a = "1" then "v" end from table;
or
select case a when "1" then "v" end from table;
记住一定要用end包住条件,对一个字段套多个case when语句只能执行一次,比如这样:
select case when name like "%a%" then replace(name,'a','A')
when name like "%b%" then replace(name,'b','B')
when name like "%c%" then replace(name,'c','C')
else name end as SB ,*
from table;
这个语句的目的是对name字段进行部分替换,他只能替换a,b,c中的一个
如果如要全部替换需要套很多个replace()
select replace(replace(replace(name,"a",A),"b","B"),"c","C") from table;
很麻烦,而且数据量大的情况下执行效率很低
日期加减用julianday():
select julianday('now') - julianday('1776-07-04');