sqlite 經常使用的一些語句

轉載:https://blog.csdn.net/qq_25221835/article/details/82768375數據庫

轉載:http://www.javashuo.com/article/p-pdgrqxje-no.html(最近10條記錄)spa

1.字段是varchar2類型即string,而其實存的是數字,這時候用order by排序.net

表數據與結構: salary 爲 varchar 類型code

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 降序blog

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
相關文章
相關標籤/搜索