目录
一、去重查询
distinct 是去重查询关键字
实例:selcte distint unversity from user
二、使用LIMIT限制结果集
LIMIT 子句可以被用于强制 SELECT 语句返回指定的记录数。
LIMIT 接受一个或两个数字参数。参数必须是一个整数常量。
如果只给定一个参数,它表示返回最大的记录行数目。
如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目。
为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1。
初始记录行的偏移量是 0(而不是 1)。
实例:select device_id from user_profile limit 2
三、修改菜单名
实例:select device_id as user_infos_examplefrom user_profile limit 2
四、范围
between:双边范围都包含
实例:select device_id,gender,age from user_profile where age between 20 and 23
不包含:!=或者not in
实例:select device_id,gender,age,university from user_profile where university != '复旦大学'
不为空:!=''或者age is not null
select device_id,gender,age,university from user_profile where age != ''
五、子查询
实例:select device_id,gender,age,university,gpa from user_profile where device_id in (select device_id from user_profile where gpa > 3.5 and university = '山东大学')or device_id in (select device_id from user_profile wh