> 文档中心 > 数据库知识点积累day02

数据库知识点积累day02


操作符混合运用

and操作符的优先级大于or

select device_id,gender,age,university,gpafrom user_profilewhere university='山东大学' and gpa>3.5 or university='复旦大学' and gpa>3.8

查看学校名称中含北京的用户

_ :下划线 代表匹配任意一个字符

% :百分号 代表匹配0个或多个字符;

[]: 中括号 代表匹配其中的任意一个字符;

[^]: ^尖冒号 代表 非,取反的意思;不匹配中的任意一个字符。

select device_id,age,university from user_profile where university like '%北京%'

查找GPA最高值

select max(gpa) from user_profile where university="复旦大学"select gpafrom user_profilewhere university='复旦大学'order by gpa desc limit 1

计算男生人数以及平均GPA

select count(gender) as male_num,round(avg(gpa),1) from  user_profile where gender ="male"

每个学校每种性别的用户数、30天内平均活跃天数和平均发帖数量

select     gender, university,    count(device_id) as user_num,    avg(active_days_within_30) as avg_active_days,    avg(question_cnt) as avg_question_cntfrom user_profilegroup by gender, university