------------恢复内容开始------------
1. select gpa
from user_profile
where university = '复旦大学'
order by gpa DESC
limit 1
或
select max(gpa)
from user_profile
where university = '复旦大学'
5. ROUND 函数用于把数值字段舍入为指定的小数位数。SQL ROUND() 语法
SELECT ROUND(column_name,decimals) FROM table_name column_name 要舍入的字段decimals 要返回的小数位数
select count(gender) as male_num,round (avg(gpa) , 1) as avg_gpa
from user_profile
where gender = 'male'
6. 聚合函数结果作为筛选条件时,不能用where,而是用having语法
select university,
avg(question_cnt) as avg_question_cnt,
avg(answer_cnt) as avg_answer_cnt
from user_profile
group by university
having avg_question_cnt < 5 or avg_answer_cnt <20
7.
select device_id,question_id,result
from question_practice_detail
where device_id=(
select device_id
from user_profile
where university='浙江大学'
)
order by question_id;
或
select q.device_id,q.question_id,q.result
from question_practice_detail q join user_profile u on q.device_id=u.device_id(两张表和在一起的条件)
where u.university='浙江大学'
order by q.question_id;
8. union all不用去重
------------恢复内容结束------------
浙公网安备 33010602011771号