练习——父子表

本文通过具体的SQL语句示例,介绍了如何实现父子表的一对多关系查询,包括查询子表信息、根据条件更新数据、统计子表记录数以及找出特定条件下的父表记录等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


父表:father  
fid fname 
1  a
2  b
3  c
4  e
  
insert into father values(1,'a');
insert into father values(2,'b');
insert into father values(3,'c');
insert into father values(4,'e');


create table father(
fid int primary key,
fname varchar(10)
);


一对多:父子表,主从(明细)表,


    
sid sname fid height money
insert into son values(100,'s1',1,1.7,8000);
insert into son values(101,'s2',2,1.6,7500);
insert into son values(102,'s3',2,1.8,8000);


create table son(
sid int primary key,
sname varchar(8),
fid int,
height decimal(10,2),
money decimal(16,2)
);


1、查询sid、sname、fid
2、查询各儿子涨价20%以后的新学费,注意,8000块以下的不涨价。
  要求同时显示所有涨价和没有涨价的学费。
3、sid、sname、fid、fname
4、fid、fname、儿子数(没有儿子的不显示)
5、fid、fname、儿子数(没有儿子的个数显示为0)
也可以用相关子查询,但是效率低,所以尽量不要用。
6、找出不止有1个儿子的father信息:fid、fname、儿子数      两种:
7、找出儿子最多的father信息:fid、fname、儿子数
8、找出fid为(1,2,4)的father中,各儿子的身高
9、找出各father中身高最高的儿子。
10、找出身高在1.8到1.65之间的所有儿子及父亲信息:fid,fname,sid,sname,height

 

答案:
2题
select sname,money,money*1.2 as new_money,'涨价' as flag
from son where money>=8000
union all
select sname,money,null,'不涨'
from son where money<8000;
4题:
select f.fid,f.fname,count(*) x
from father f join son s on f.fid=s.fid
group by  f.fid,f.fname
5题:
select f.fid,f.fname,count(s.sid) x
from father f left join son s on f.fid=s.fid
group by  f.fid,f.fname
6题:
select f.fid,f.fname,count(*) x
from father f join son s on f.fid=s.fid
group by  f.fid,f.fname
select f.fid,f.fname,count(*) x
from father f join son s on f.fid=s.fid
group by  f.fid,f.fname
having count(*)>1

select * from (
 select f.fid,f.fname,count(*) x
 from father f join son s on f.fid=s.fid
 group by  f.fid,f.fname
) t
where x>1;
7题:
select f.fid,f.fname,count(*) x
from father f join son s on f.fid=s.fid
group by  f.fid,f.fname
having count(*)=(
  select max(count(*)) from son group by fid
);

select f.fid,f.fname,count(*) x
from father f join son s on f.fid=s.fid
group by  f.fid,f.fname
having count(*)=(
  select max(rs) from (select count(*) rs from son group by fid) t
);

 

初学Vue的案例练习题可以从以下几个方面进行练习: 1. 组件的基本使用:创建一个Vue组件,在模板中展示一些静态文本或数据,并在组件中定义一些基本的数据和方法。 2. 数据绑定:练习使用v-model指令和数据绑定来实现双向数据绑定,例如创建一个表单,实时显示输入框中的内容。 3. 列表渲染:使用v-for指令来循环渲染一个数组或对象的数据,并在模板中展示列表数据。 4. 条件渲染:使用v-if和v-else指令来根据条件动态地展示或隐藏一些元素。 5. 事件处理:练习使用v-on指令来监听DOM事件,并在事件处理函数中修改数据或执行其他逻辑。 6. 组件通信:练习使用props和emit来实现父子组件之间的数据传递和通信。 7. 生命周期:了解Vue的生命周期钩子函数,练习在创建、更新和销毁组件时执行相应的逻辑。 8. 路由和导航:学习使用Vue Router插件来实现前端路由和导航功能,创建不同路径下的页面。 9. 状态管理:学习使用Vuex插件来实现全局状态管理,练习在不同组件之间共享和修改状态。 以上是初学Vue时可以练习的一些案例题目,你可以根据自己的学习进度和需求选择适合自己的练习项目。如果需要更多详细的案例和代码实例,你可以参考中提供的学习资料和中的项目案例地址。另外,你还可以在Vue官方文档和在线教程中找到更多的实例和练习题目进行学习。希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Vue3+TypeScript从入门到进阶(三)——Vue3基础知识点(上)——附沿途学习案例及项目实战代码](https://blog.youkuaiyun.com/wuyxinu/article/details/124639124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值