当前位置: 首页 > news >正文

ps建设此网站的必要与可行性手机做logo用什么网站

ps建设此网站的必要与可行性,手机做logo用什么网站,wordpress自动发布文章待审,公司网站建设需要哪些大家好,我是空空star,本篇带大家了解一道中等的力扣sql练习题。 文章目录前言一、题目:608. 树节点二、解题1.正确示范①提交SQL运行结果2.正确示范②提交SQL运行结果3.正确示范③提交SQL运行结果4.正确示范④提交SQL运行结果5.其他总结前言 …

大家好,我是空空star,本篇带大家了解一道中等的力扣sql练习题。

文章目录

  • 前言
  • 一、题目:608. 树节点
  • 二、解题
    • 1.正确示范①
      • 提交SQL
      • 运行结果
    • 2.正确示范②
      • 提交SQL
      • 运行结果
    • 3.正确示范③
      • 提交SQL
      • 运行结果
    • 4.正确示范④
      • 提交SQL
      • 运行结果
    • 5.其他
  • 总结


前言


一、题目:608. 树节点

给定一个表 tree,id 是树节点的编号, p_id 是它父节点的 id 。

+----+------+
| id | p_id |
+----+------+
| 1  | null |
| 2  | 1    |
| 3  | 1    |
| 4  | 2    |
| 5  | 2    |
+----+------+

树中每个节点属于以下三种类型之一:
叶子:如果这个节点没有任何孩子节点。
根:如果这个节点是整棵树的根,即没有父节点。
内部节点:如果这个节点既不是叶子节点也不是根节点。

写一个查询语句,输出所有节点的编号和节点的类型,并将结果按照节点编号排序。上面样例的结果为:

+----+------+
| id | Type |
+----+------+
| 1  | Root |
| 2  | Inner|
| 3  | Leaf |
| 4  | Leaf |
| 5  | Leaf |
+----+------+

解释
节点 ‘1’ 是根节点,因为它的父节点是 NULL ,同时它有孩子节点 ‘2’ 和 ‘3’ 。
节点 ‘2’ 是内部节点,因为它有父节点 ‘1’ ,也有孩子节点 ‘4’ 和 ‘5’ 。
节点 ‘3’, ‘4’ 和 ‘5’ 都是叶子节点,因为它们都有父节点同时没有孩子节点。
样例中树的形态如下:

注意
如果树中只有一个节点,你只需要输出它的根属性。

二、解题

1.正确示范①

提交SQL

select id,
case when p_id is null then 'Root' 
when id in (select p_id from tree) then 'Inner'
else 'Leaf' end Type
from tree
order by id;

运行结果

2.正确示范②

提交SQL

select id,
if(p_id is null,'Root',if(id in (select p_id from tree),'Inner','Leaf')) Type
from tree
order by id;

运行结果

3.正确示范③

提交SQL

select id,'Root' Type
from tree
where p_id is null
union all 
select id,'Inner' Type
from tree
where id in(select p_id from tree 
)
and  p_id is not null 
union all 
select id,'Leaf' Type
from tree
where id not in(select p_id from tree where p_id is not null 
)
and p_id is not null
order by id;

运行结果

4.正确示范④

提交SQL

select id,'Root' Type
from tree
where p_id is null
union 
select id,'Inner' Type
from tree
where id in(select p_id from tree 
)
and  p_id is not null 
union 
select id,'Leaf' Type
from tree
where id not in(select p_id from tree where p_id is not null 
)
and p_id is not null
order by id;

运行结果

5.其他


总结

正确示范①思路:
采用case when 语句
case when p_id is null then 'Root'
when id in (select p_id from tree) then 'Inner'
else 'Leaf' end Type
正确示范②思路:
采用 if 语句
if(p_id is null,'Root',if(id in (select p_id from tree),'Inner','Leaf')) Type
正确示范③思路:
采用union all 语句
正确示范④思路:
采用 union 语句

http://www.yayakq.cn/news/980148/

相关文章:

  • 大连做网站的网络公司广告设计与制作需要学什么专业
  • 南昌比较好的网站设计wordpress门户型多栏设计
  • wordpress微博同步织梦与wordpress seo哪个好
  • c2c网站开发毕业设计网站建设工具有哪些品牌
  • 用excel可以做网站网站中qq跳转怎么做的
  • 平顶山股票配资网站建设优质ppt模板免费下载
  • 网站建设费长期待摊费用网站icp备案号怎么查询
  • 视频策划方案怎么写郑州网站seo优化
  • cms建站系统开源microsoft做网站
  • 网站开发工具的功能包括html软件开发前端和后端
  • 网站开发顶岗报告那个网站seo做的好的
  • 网站建设主要有哪些成本中国建设银行网站e路
  • 抖音做我女朋友网站网站开发的内容
  • 建设工程管理是干嘛的志鸿优化设计
  • 海外酒店 网站建设99作文网
  • 小装修网站开发费用做哪个外贸网站不用交费
  • 推荐一本学做网站的书网站模板自建站
  • 如何对网站做进一步优化企业关键词大全
  • 微信公众号微网站开发类型网站链接建设的作用
  • c++可以做网站吗icp网站建设
  • 做移动端网站软件开发品牌营销策划方案模板
  • 百度网站制作公司2023网络营销案例分析
  • 没有公司怎么做网站网上智慧团建登录入口
  • 网站建设方案书 人员资金安排建设移动网站
  • 手机做图纸app下载网站学程序员需要什么基础
  • 网络推广网站建设方案网站开发技术与功能 需求说明
  • 专业网站设计学校wordpress 右边栏
  • 兴义做网站wordpress开启xml rpc
  • 网站开发所需的知识厦门外贸网站建设
  • 电脑版和手机版网站怎么做的建筑工程类招聘网站