赞助

sqlite 常用的一些语句

转载:https://blog.csdn.net/qq_25221835/article/details/82768375

转载:https://blog.csdn.net/qq_35449730/article/details/82955979(最近10条记录)

1.字段是varchar2类型即string,而其实存的是数字,这时候用order by排序

表数据与结构: salary 为 varchar 类型

create table TEST_ROW_NUMBER_OVER(
       id varchar(10) not null,
       name varchar(10) null,
       age varchar(10) null,
       salary varchar(10) null
);
 
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(1,'a',10,'8000');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(1,'a2',11,'6500');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(2,'b',12,'13000');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(2,'b2',13,'4500');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(3,'c',14,'3000');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(3,'c2',15,'20000');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(4,'d',16,'30000');
insert into TEST_ROW_NUMBER_OVER(id,name,age,salary) values(5,'d2',17,'1800');

以 salary 降序

select id,name,age,salary from TEST_ROW_NUMBER_OVER order by cast(salary as integer) desc

 

2.查询数据库中最近的十条数据,并按时间升序进行排列

select *from ( select * from table1 order by datetime desc limit 0,10 ) order by datetime

 

posted @ 2019-05-24 17:32  车臣  阅读(661)  评论(0编辑  收藏  举报