【SQL server】教材数据库(4)

学生(学号,年龄,性别,系名)

教材(编号,书名,出版社编号,价格)

订购(学号,书号,数量)

出版社(编号,名称,地址)

根据上面基本表的信息完成下列查询。

1统计每位学生订数数量

2 统计每位学生应缴书费。

3 统计订购1000册以上的教材信息。

4 统计没有人定的教材信息。

1、use jiaocai

select student.id,student.age,student.sex,student.dept,count(orders.number) AS 订书数量 from student

left join orders on student.id = orders.s_id

group by student.id,student.age,student.sex,student.dept;

2、select student.id, student.age ,student.sex, student.dept, sum(book.price * orders.number) AS 应缴书费

from student

left join orders on student.id = orders.s_id

left join book on orders.b_id = book.id

group by student.id, student.age ,student.sex, student.dept;

3、由于插入的数据不能满足题目要求,需要修改订购表中的值

select book.id, book.title, book.c_id, book.price

from orders

join book on orders.b_id = book.id

group by book.id, book.title, book.c_id, book.price

having sum(orders.number) >= 1000;

4、组合查询:select jiaocai.bianhao, jiaocai.shuming, jiaocai.chubanshebianhao, jiaocai.jiage

from jiaocai

union

select jiaocai.bianhao, jiaocai.shuming, jiaocai.chubanshebianhao, jiaocai.jiage

from jiaocai

where jiaocai.bianhao not in (select dinggou.shuhao from dinggou);

嵌套查询:select book.id, book.title, book.c_id, book.price

from book

where book.id in (select book.id from book)

or book.id not in (select orders.b_id from orders);

相关推荐
天空'之城29 分钟前
单片机基础核心知识点汇总(三十三)
数据库·单片机·嵌入式硬件
爱吃苹果的日记本2 小时前
数据结构第一课
c语言·数据结构·数据库·学习·c#
张小姐的猫2 小时前
【AI大模型接入SDK】 —— Gemini接入封装
android·数据结构·数据库·c++·人工智能·python
Thomas21432 小时前
mysql 索引面试复习
数据库·mysql·面试
Elastic 中国社区官方博客3 小时前
Elasticsearch Python DSL 客户端开发
大数据·数据库·python·elasticsearch·搜索引擎·全文检索
风哥2号3 小时前
数据库教程FGMT03‑生产环境Linux+Oracle19c+ASM安装配置与项目实战
linux·数据库
龙亘川3 小时前
旅游强国建设|一网统管智慧旅游服务模块,赋能节假日文旅数字化治理
大数据·数据库·人工智能·科技·智慧城市·旅游
星火跨境XINGHUOS3 小时前
技术向辨伪:从商标查证到源码资产,如何核验网络上的z真假“星火跨境“
数据库
Databend4 小时前
只看 PASS 会骗你,6 条 Agent Trace 里的 Coding Agent 评测真相
大数据·数据库·agent