首先创建users表
create table users(
id serial primary key,
player varchar(255) not null,
score real,
team varchar(255)
)
插入记录并select
insert into users(player,score,team) values
('库里',28.3,'勇士'),
('哈登',30.2,'火箭'),
('阿杜',25.6,'勇士'),
('阿詹',27.8,'骑士'),
('神龟',31.3,'雷霆'),
('白边',19.8,'热火');
查询所有记录:select * from users
这就是users中所有的记录
- order by:排序。asc(升序,默认为asc),desc(降序)
- limit:限制 SELECT 语句中查询的数据的数量。也就是从表中从上到下取出指定的记录数
- offset:偏移。从一个特定的偏移开始提取记录
select * from users order by score;//默认为升序
select * from users order by score asc;//升序
select * from users order by score desc;//降序
select * from users order by team;//拼音首字母排序,如果首字母相同,则排拼音第二个字母,以此类推
select * from users order by team,score;//先对team升序排序,再在排序后的表中对score升序排序。如下
select * from users order by team,score desc;//先对team升序排序,再在排序后的表中对score降序排序。如下
select * from users order by score desc limit 4
select * from users order by score desc limit 4 offset 1