標籤:知識 注意 無符號 自動填滿 cas 預設 原來 成績 class
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、
資料庫知識點