单表查询——select * from 表名
单字段查询——select 字段名 from 表名
多字段查询——select 字段名1,字段名2 from 表名(多字段查询时只需用逗号将字段名隔开即可)
字段别名——select x as zy from 表
或者 select x as “z y” from ##表查询结果中显示的字段名为大写字母,如果别名中包含空格、特殊字符(例如%)或者对大小写敏感,则别名需要使用双引号引起来##
条件查询:where
单条件——select * from student where name=徐大炮
多条件——where多条件:select * from student where ID=2 and name=‘徐大炮’
模糊查询:like
聚合函数:count、sum、max、min、avg
5.MySQL函数
now():获取当前时间
year() :获取年份
month():获取月份
date():获取日期
day():获取天数
length():获取字符串长度
concat():组合字符串
order by:
对查询结果进行排序,必须置于SQL语句的最后,语法:order by {column_name1, column_name2, column_name3, ......column_namen} [asc|desc]
说明:
a、{column_name1, column_name2, column_name3, ......column_namen}:指定需要排列的字段。
b、[asc|desc]:指定排列策略,asc以升序排列,desc以降序排列,默认以升序排列。
不同数据类型,升序的含义如下:
①数字类型:小值在前面显示;
②日期类型:早的日期在前面显示;
③字符类型:依据字母顺序显示,a在前,z最后;
④空值:显示在最后。
去除重复——distinct
select age from student查询结果为13,13,13
select distinct age from student查询结果为13