1、查询字段是字符串,但想按照数值排序,有以下几种方法:
1.order by price+0 desc
2.order by CAST(price as SIGNED) desc
3.order by CONVERT(price,SIGNED) desc
2、分页查询
select * from car limit 0,10? #分页查询,跳过几条数据(0)取几条(10)
规定一个每页显示的条数:m
当前页数:n]
select * from car limit (n-1)*m,m
3、zerofill,表示自动填0,和默认值为0差不多.
unsigned,表示该字段存放一个无符号值,只存正数,不存负数。
故unsigned zerofill是无符号补零的意思。
例如:a的值由原来的1变为0001,这就是ZEROFILL属性的作用,如果宽度小于设定的宽度(这里宽度为4),则自动填充0,需要注意的是,这只是最后显示的结果,在MySQL中实际存储的还是1。
4、
查询出培优班成绩最差的学员信息(成绩最差的不一定是一个人)
select * from student where class_no = (select class_no from class where class_name = "培优班") and grade = (select min(grade) from student where class_no = (select class_no from class where class_name = "培优班"));
select * from student where (class_no,grade) = (select class_no,min(grade) from student natural join class where class_name = "培优班");
查询出普通班成绩最好的学员信息
select * from student natural join class where class_name = "普通班" order by grade desc limit 1;
select * from student where (class_no,grade) = (select class_no,max(grade) from student natural join class where class_name = "培优班");
5、