列去重操作
1、使用DISTINCT关键字去重
SELECT DISTINCT(university)
FROM user_profile
2、使用GROUP BY分组,分组回导致建立临时表
SELECT university
FROM user_profile
GROUP BY university
查询结果限制返回行数
select device_id from user_profile limit 2;
select device_id from user_profile limit 0,2;
select device_id from user_profile where id <=2;
limit 0,2表示从第一条数据开始(0代表第一条),每页只显示2条数据
第一个数字表示起始地址,第二个表示偏移量
查找除复旦大学的用户信息
select device_id, gender,age,university from user_profile where university!="复旦大学"
用where过滤空值练习
select device_id,gender,age,university from user_profile where age is not null
select device_id,gender,age,university
from user_profile
where age !='
Where in 和Not in
select device_id ,gender,age,university,gpa from user_profile where university in('北京大学','复旦大学','山东大学')
本文介绍了SQL中去除重复数据的两种方法,使用DISTINCT关键字和GROUP BY语句,并展示了如何限制查询结果的返回行数。此外,还讲解了如何通过WHERE子句过滤特定条件,如排除特定大学的用户信息,以及处理空值。同时,演示了使用IN和NOT IN操作符进行多条件筛选。
569

被折叠的 条评论
为什么被折叠?



