#²éѯѧÉúµÄÐÕÃû SELECT age from student; #SELECT ---->²éѯ¹Ø¼ü×Ö #select ºó¸úÒª²éѯµÄÊֶΠ#from ºó±ã¸úÒª²éѯµÄÐÕÃû
#²éѯѧÉúÐÕÃûºÍÐÔ±ð SELECT name ,sex, from student;
#²éѯѧÉúµÄÈ«²¿ÐÅÏ¢ select * from student;
#Ìõ¼þ²éѯ°à¼¶ºÅΪ20201001µÄѧÉú SELECT * from student where class_num = '20201001"; #3.²éѯ¶àÁÐ,·Ö¸î #²éѯ°à¼¶ºÅΪ20201001°àµÄѧÉúµÄÐÕÃûºÍÐÔ±ðºÍÄêÁä SELECT name ,age,sex from student where class_num='20201001' #<> #4.²éѯ³öÄêÁäÔÚ21 µ½25 µÄͬѧ SELECT *from student where age between 21 and 25; #5.¶àÌõ¼þ #²éѯ³ö°à¼¶ºÅΪ20201001°àµÄÄÐͬѧ SELECT*from student where class_num = '20201001' and sex = 'ÄС¯ #²éѯ°à¼¶ºÅΪ20201001 ºÍ20201002µÄͬѧ SELECT*FROM student where class_num='20201001' or class_num ='20201002';
#6. in °üº¬---¡·Í¬Ò»¸ö×Ö¶ÎÏ°üº¬¶à¸öÖµ ²éѯidΪ 1ºÍ3µÄͬѧ SELECT *from student where id in(1,3) ??
#7.Ä£ºý²éѯ--¡·¶àʹÓÃÓë×ÊÔ´ËÑËØ ? #like --->ͨÅä·û(_:µ¥¸ö×Ö·û,%Æ¥ÅäÈÎÒâ×Ö¶Î) #²éѯËùÓÐÍõͬѧ SELECT * from student where name like 'Íõ%' 3²éѯ³öËùÓдøÓÐÍõµÄͬѧ SELECT*FROM student where name like '%Íõ%';
#·Ö×é²éѯ/¾ÛºÏ²éѯ #sum() ------>ÇóºÍ #avg() ------->ƽ¾ùÊý #max() ------->È¡×î´óÖµ #min() ------->È¡×îСֵ #count() ------>È¡¼Ç¼ֵ # 1.ÇóѧÉúµÄÄêÁä×ÜºÍ SELECT sum(age) from student; #2.ÇóѧÉúµÄƽ¾ùÄêÁä SELECT avg(age) from student; #3.ÇóѧÉúµÄ×î´óÄêÁä SELECT max(age) from student; #SELECT max(age) ,name from student ;×¢Òâ ÎÒÃÇÖ»Äܲé³öÕâ¸öÖµ µ«²»Äܲé³öÕâ¸öÖ»ÊÇ˲úÉúµÄ #4.ÇóѧÉúµÄ×îСÄêÁä SELECT min(age) from student; #5.count------> #count(*)±íʾȥ²éѯ±íÖеÄËùÓмǼ SELECT count(*) from student; #count(×Ö¶ÎÃû)²»»áͳ¼ÆΪ¿ÕµÄ×ֶΠSELECT count(class_num) from student;
#GROUP BY + ×Ö¶ÎÃû #ͨ¹ý×ֶνøÐзÖ×é SELECT avg(age),class_num from student GROUP BY class_num; #7.²éѯ³ö¸÷¸ö°àÄêÁäµÄ×î´óÖµ SELECT max(age),class_num FROM student GROUP BY class_num;
#8.²éѯ³ö¸÷¸öÄêÁä¶ÎµÄ·ÖÊý×î´óÖµ SELECT MAX(grade),class_age FROM student GROUP BY class_age; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? #ÅÅÐò ORDER BY + ×Ö¶Î(ÊýÖµÀàÐ͵Ä×Ö¶Î) SELECT * from student ;#²éѯµ½µÄÊý¾Ý ----¡·´ÓСµ½´ó¸ù¾Ýid½øÐеÄÅÅÐò #¸ù¾ÝÄêÁä½øÐÐÅÅÐò SELECT * from student ORDER BY age; #¸ù¾ÝÄêÁä´ÓСµ½´óÅÅÐò SELECT *from student ORDER BY age DESC #DESC ´ú±íµ¹Ðð;´Ó´óµ½Ð¡ÅÅÐò #ASC ´ú±íÕýÐò;´ÓСµ½´óÅÅÐò #¸ù¾ÝѧºÅÉýÐò,°´ÕÕÄêÁë½µÐò ----¡·¶à¸ö×Ö¶ÎË¸ß OEDER BY ¶ÔËÆð×÷Óà SELECT *from ?student ORDER BY sno ASC,age DESC; SELECT*from student ORDER BY age DESC,sno ASC;
#·ÖÒ³²éѯ*(ÏÞÖƲéѯ) SELECT*from student; #limit ÏÞ¶¨µÄÌõÊý offset ´ÓÄÇÒ»Ìõ¿ªÊ¼²éѯ(ĬÈÏ´ÓÁ㿪ʼ) SELECT * from student LIMIT 3 OFFSET 0;#µÚÒ»Ò³ SELECT*from student LIMIT 3 OFFSET 3;#µÚ¶þÒ³ÿÿÿ SELECT * from student LIMIT 3 OFFSET 6;#µÚÈýÒ³ #ÏëÒª×ö·ÖÒ³²éѯ----¡·ÐèÒª¸øÊý¾Ý¿âÁ½¸ö²ÎÊý:pageSize:ÿһҳ²éѯµÄÌõÊý----¡·15Ìõ #?? ??? ??? ??? ? ? ? ? ?pageIndex:µ±Ç°Ò³ÂëÊý #select*from ±í LIMIT pageSize OFFSET pageSize *(pageIndex-1) #limit ´ÓÄÇÒ»Ò³¿ªÊ¼²éѯ,ÏÞ¶¨µÄÌõÊý SELECT * from student LIMIT 0,3; ?
|