美文网首页
爸爸在哪儿?(皇位继承图)

爸爸在哪儿?(皇位继承图)

作者: 长振 | 来源:发表于2020-11-16 15:11 被阅读0次
image.png

开创新朝

节点的边框颜色或线段颜色有变的视为开创了新王朝,图示绿色所示的都是新王朝。
值得注意的是长剪头的7个类似五代十国,要视为一个整体(取长兄作为朝代名)


image.png

数据的iamroot计算出了上图的绿色点(新朝开创者)

-- 跟父亲的type、class不同或没有父亲的为本朝的root
create table find_father_root as 
select a.*,case when (a.po_type<>b.po_type or a.tiny_class <> b.tiny_class or b.style_id is null) then a.style_id end as iamroot
from ods.sku_path1030 a
left join ods.sku_path1030 b on a.repeat_style_id=b.style_id --b是父表
where a.style_path like '%117201600%'
order by a.style_path

填充空白(找祖宗,本朝的)

create table find_father_myroot as 
select a.style_id,a.repeat_style_id,a.po_type,a.style_path,coalesce(a.iamroot,max(b.iamroot)) my_root
from find_father_root a 
left join find_father_root b on instr(a.style_path,b.iamroot)>0
group by a.style_id,a.repeat_style_id,a.po_type,a.style_path,a.iamroot
image.png

朝代合并

potype为fast且父辈的root相同的予以合并


image.png
select a.style_id,a.style_path,b.my_root froot,a.my_root 
, min(a.my_root) over (partition by b.my_root) new_root
from find_father_myroot a
left join find_father_myroot b on a.repeat_style_id=b.style_id
order by a.style_path

最终结果


image.png
image.png

小调整:非fast的不要合并

select a.style_id,a.style_path,b.my_root froot,a.my_root 
,case when a.po_type='Fast-track Repeat' then min(a.my_root) over (partition by a.po_type,c.my_root) else a.my_root end as new_root
from find_father_myroot a
left join find_father_myroot b on a.my_root=b.style_id --找上个朝代
left join find_father_myroot c on b.repeat_style_id=c.style_id --找上个朝代的开国
order by a.style_path
image.png

dag图

-- 画graph----------------------------------------------
create table ods.sku_path_dot as --drop table ods.sku_path_dot
select  repeat_style_id ,style_id ,po_type,tiny_class,style_path,root_style_id,
    dense_rank() over(partition by root_style_id order by po_type ) po_type_rk,
    dense_rank() over(partition by root_style_id order by tiny_class ) tiny_class_rk
from ods.sku_path1030
-- 点
select distinct concat('"',style_id,'"',
    case when tiny_class_rk=1 then '[color=red]' 
    when tiny_class_rk=2 then '[color=yellow]'
    when tiny_class_rk=3 then '[color=green]'
    when tiny_class_rk=4 then '[color=blue]'
end) as graphviz
from sku_path_dot where style_path like '%117201600%' --and repeat_style_id is not null
-- 边
union all
select concat('"',repeat_style_id,'" -> "' ,style_id,'"',case when po_type='Fast-track Repeat' then '[color=pink]' else '' end) as graphviz
from sku_path_dot where style_path like '%117201600%' and repeat_style_id is not null
union all 
select '}'

http://www.webgraphviz.com/
登录网址在线出图:
复制下面2行,再加上上面代码跑出来的结果(本想放sql一起,顺序会乱)。

digraph G {
rankdir=LR
#上面sql结果

相关文章

  • 爸爸在哪儿?(皇位继承图)

    开创新朝 节点的边框颜色或线段颜色有变的视为开创了新王朝,图示绿色所示的都是新王朝。值得注意的是长剪头的7个类似五...

  • 时间的力量-读《明朝那些事》

    朱祁镇是明朝的第六个皇帝,相比于他爷爷要和弟弟争皇位,他爸爸要和叔叔争皇位,他8岁就以太子的身份继承了皇位,而且他...

  • 趣谈英国王位的继承

    英国王位的继承与中国古代的皇位继承不一样。中国古代封建社会的皇位继承基本上是嫡长子继承制。而英国王位的继承却有迥然...

  • 虽然没皇位需要继承,但总是有遗产需要继承吧

    虽然没皇位需要继承,但总是有遗产需要继承吧 有一位网友说:“只要能处理好遗产继承问题,生几个无所谓。虽然家里没皇位...

  • 有皇位继承啊?

    村长家的儿小儿媳生了个女孩,可把村长两口子给气坏了,小儿媳是个外地人,叫于梦梦,是读大学的时候和杨大志认识的,都谈...

  • 浅谈皇位继承问题

    儿子笨笨看完三国漫画,问道:“刘禅不是当皇帝的料,为什么让他当皇帝?” 亦明答道:“”刘禅是太子,是皇帝的接班人,...

  • 那些最受宠的儿子

    即使很多人说大清都灭忙100多年了,家里还有皇位继承啊? 是的,他家没有皇位,但是在很多农村生一个儿子继承香火,还...

  • 0930:一命二运三风水四积阴德五读书

    一命二运三风水四积阴德五读书。虽然可以改运气,但天命不可违,本来嘉靖帝作为皇位的第六顺位继承人,成功继承皇位的概率...

  • 愁死人的汉成帝,愁死人的西汉后期 | 资治通鉴

    愁死人的汉成帝,愁死人的西汉后期 | 资治通鉴 图 | 桃源仙境 公元前三三年,汉元帝驾崩,皇太子刘骜继承皇位,成...

  • “皇位继承”惨案——乡村版

    张家村的张翠花生得如花似玉,却因为生母早逝,继母做主将她嫁给了太阳村的王家独子。结婚5年,翠花生了3个女娃,因此...

网友评论

      本文标题:爸爸在哪儿?(皇位继承图)

      本文链接:https://www.haomeiwen.com/subject/bpsdvktx.html