Database knowledge point accumulation day02

operator mix

The and operator takes precedence over or

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

View users with Beijing in their school name

_ : Underscore means match any character;

% : The percent sign means match 0 or more characters;

[]: Brackets represent matching any one of the characters;

[^]: ^The pointed colon means not and negation; it does not match any one of the characters.

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

Find the highest GPA

select max(gpa) from user_profile where university="复旦大学"

select gpa
from user_profile
where university='复旦大学'
order by gpa desc limit 1

Calculate the number of boys and the average GPA

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

Number of users per gender per school, average active days in 30 days, and average number of posts

select 
    gender, university,
    count(device_id) as user_num,
    avg(active_days_within_30) as avg_active_days,
    avg(question_cnt) as avg_question_cnt
from user_profile
group by gender, university

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324081330&siteId=291194637