sql经典实例
### 一、学生成绩数据统计
查询班级全体学生成绩平均分:
```sql
SELECT AVG(score) FROM student WHERE class_id = 'S001'
```
查询各科学生平均成绩:
```sql
SELECT subject, AVG(score) FROM student GROUP BY subject
```
查询某班级某科大于90分人数:
```sql
SELECT COUNT(*) FROM student WHERE class_id = 'S001' AND subject = 'Math' AND score > 90
```
查询某科不及格学生总数:
```sql
SELECT COUNT(*) FROM student WHERE subject = 'Math' AND score < 60
```
### 二、用户信息查询
sql存储过程实例查询年龄大于30岁的用户:
```sql
SELECT * FROM user WHERE age > 30
```
查询某个地区(城市)的用户:
```sql
SELECT * FROM user WHERE city = 'Beijing'
```
查询某个时间段注册的用户:
```sql
SELECT * FROM user WHERE register_date BETWEEN '2016-01-01' and '2016-12-31'
```
查询某个时间段活跃的用户:
```sql
SELECT * FROM user WHERE last_login_time BETWEEN '2017-01-01' and '2017-12-31'
```
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论