select column1,column2, ... from table_name order by column1,column2,....
create table ky (id int,name varchar(10) primary key not null ,score decimal(5,2),address varchar(20),hobbid int(5));
insert into ky values(1,'liuyi',80,'beijing',2);
insert into ky values(2,'wangwu',90,'shengzheng',2);
insert into ky values(3,'lisi',60,'shanghai',4);
insert into ky values(4,'tianqi',99,'hangzhou',5);
insert into ky values(5,'jiaoshou',98,'laowo',3);
insert into ky values(6,'hanmeimei',10,'nanjing',3);
insert into ky values(7,'lilei',11,'nanjing',5);
select * from ky; //查询ky表
mysql> select id,name,score from ky order by score;
mysql> select id,name,score from ky order by score desc;
mysql> select name,score from ky where address='nanjing' order by score desc; //将地址是南京的学生分数按降序排列
mysql> select id,name,hobbid from ky order by hobbid desc,id desc;
mysql> select id,name,hobbid from ky order by hobbid desc,id;
在这里插入代码片
mysql> select * from ky where score > 70 and score <=90; //查询分数在大于70且小于等于90
mysql> select * from ky where score > 70 or score <=90; //查询分数大于70或小于等于90分的
mysql> select * from ky where score > 70 or (score >75 and score <90);
select distinct 字段 from 表名
mysql> select distinct hobbid from ky;
select column_name, aggregate_function(column_name)from table_name where column_name operator valueGROUP BY column_name;
mysql> select count(name),hobbid from ky group by hobbid;
mysql> select count(name),hobbid from ky where score>=80 group by hobbid;
mysql> select count(name),score,hobbid from ky where score>=80 group by hobbid order by count(name) asc;
select column1,column2, ... from table_name limit [offset,] number
mysql> select * from ky limit 3;
mysql> select * from ky limit 3,3;
mysql> select id,name from ky order by id limit 3;
mysql> select id,name from info order by id desc limit 3;
*对于列的别名格式
select column_namr as alias_name from table_name;
select column_name(s) from table_name as alias_name;
select name as 姓名,score as 成绩 from ky;
select i.name as 姓名,i.score as 成绩 from info as i;
mysql> select count(*) as number from ky;
mysql> select count(*) number from ky;
mysql> create table kj as select * from ky;
mysql> mysql> create kj (select * from ky);
mysql> create table kw as select * from ky where score >=60;
% //%表示零个、一个或多个字符
_ //下划线表示单个字符
mysql> select id,name from ky where name like 'l%';
select id,name from info where name like 'c_ic_i';
mysql> select id,name from ky where name like '%i%';
mysql> select id,name from ky where name like 'wan___';
mysql> select id,name from ky where name like 'l%_';