Where A and B
where A or B
Where in
Where Not in
sum()、count()、round()、avg()这三种函数的运用
count():计算数量;
round(column_name,decimals):指定字段的小数位数,column_name为字段名,decimals为指定的小数位数;
avg():计算平均值
group by ()
order by ()
示例:user_profile
| id | device_id | gender | age | university | gpa |
| 1 | 2138 | male | 21 | 北京大学 | 3.4 |
| 2 | 3214 | male | 复旦大学 | 4.0 | |
| 3 | 6543 | female | 20 | 北京大学 | 3.2 |
| 4 | 2315 | female | 23 | 浙江大学 | 3.6 |
| 5 | 5432 | male | 25 | 山东大学 | 3.8 |
- select device_id, gender, age, university, gpa
- from user_profile
- where gender = 'male' and gpa > 3.5
根据输入,你的查询应返回以下结果:
| device_id | gender | age | university | gpa |
| 3214 | male | 复旦大学 | 4.0 | |
| 5432 | male | 25 | 山东大学 | 3.8 |
- select device_id, gender, age, university, gpa
- from user_profile
- where university = '北京大学' or gpa > 3.7
返回以下结果:
| device_id | gender | age | university | gpa |
| 2138 | male | 21 | 北京大学 | 3.4 |
| 3214 | male | 复旦大学 | 4.0 | |
| 6543 | female | 20 | 北京大学 | 3.2 |
| 5432 | male | 25 | 山东大学 | 3.8 |
- select device_id, gender, age, university, gpa
- from user_profile
- where university in ('北京大学','复旦大学','山东大学')
根据输入,你的查询应返回以下结果:
| device_id | gen |