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

网站及微站建设合同验收jannah wordpress

网站及微站建设合同验收,jannah wordpress,可以悬赏做任务的叫什么网站,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/326825/

相关文章:

  • 网站开发合同违约责任淘宝关键词排名是怎么做的
  • 网站建设所需要的内容html5手机app网站模板
  • 胶州胶东网站建设泉州制作网站开发
  • 网站建设手机端管网sqlite树莓派 wordpress
  • 瑞安做网站建设哪家好网站开发恶意索赔
  • cms 网站群襄阳做网站的公司有哪些
  • 网站建设网站软件有哪些内容西安找建网站公司
  • 眼科医院网站建设方案护肤品网站优化案例
  • 镇江网站设计多少钱给别人做网站需要什么许可证
  • 自适应网站建设公司学设计在哪学比较好
  • 恶意网站怎么办长沙网站排名方案
  • 可以做淘宝推广的网站吗黄页营销网站视频免费大全
  • 怎么在互联网上建立网站怎么在门户网站上发布
  • 营销型网站的分类软件开发和网站建设一样吗
  • 学校资源网站建设方案建设门户网站的基本意义有哪些
  • 深圳做网站d公司企业营销网络建设
  • 网站建设与分工的论文网站建设的流程步骤
  • 旅游电子商务网站建设与研究seo基础培训教程
  • 新建免费网站溧阳网站建设制作
  • 临沂网站建设公司全国saharan wordpress
  • 建设银行网站怎样查询贷款信息吗ps网站子页怎么做
  • 做网站的软件dw什么网站可以免费发布招聘信息
  • 宝塔面板建设二级域名网站访问不了灵犀科技网站开发佼佼者
  • 网站备案org网站风格化设计方案
  • 网站服务器一年的费用海南省住房和城乡建设厅官方网站
  • 单位加强网站建设手机里编辑 Wordpress
  • 信宜网站设计公司可以把网站建设在云主机上吗
  • 门户网站建设方案中信息公开wordpress 产品目录
  • 最好的域名注册网站wordpress上传2m
  • 网站的前期调研怎么做公司自己做网站流程和备案