簡體   English   中英

如何獲得親子關系的孩子人數

[英]How to get the child count for parent child relationship

使用此查詢將獲得結果,如下圖所示

select c.property_title,b.property_title as building,d.property_title as floor,e.house_name as house,
    f.room_no as room,g.bed_no as bed
    from g_property_group c
    left join g_property_group b on b.parent_id = c.id and b.is_deleted = '0'
    left join g_property_group d on d.parent_id = b.id and d.is_deleted = '0'
    left join g_house e on e.property_group_id = d.id and e.is_deleted = '0'
    left join g_room f on f.house_id = e.id and f.is_deleted = '0'
    left join g_bed g on  g.room_id = f.id and g.is_deleted = '0'
    where c.id = 'a976df373f75d3f8cc49938ae9fead8e4fc8ad19'
    and c.is_deleted = '0'

點擊這里查看圖片

單擊此處查看層次結構

我寫了獲取父母和孩子的數量的查詢。將建築物數量作為7樓層數量作為7房屋數量作為5房間數量作為4,而不是建築物的數量應為2,樓層= 2,房屋= 4 ,房間= 5,床位為1。

select c.property_title,count(b.property_title)as building,count(d.property_title)as floor,count(e.house_name)as house,
count(f.room_no)as room,count(g.bed_no) as bed
from g_property_group c
left join g_property_group b on b.parent_id = c.id and b.is_deleted = '0'
left join g_property_group d on d.parent_id = b.id and d.is_deleted = '0'
left join g_house e on e.property_group_id = d.id and e.is_deleted = '0'
left join g_room f on f.house_id = e.id and f.is_deleted = '0'
left join g_bed g on g.house_id = g.id and g.room_id = f.id and g.is_deleted = '0'
where c.id = 'a976df373f75d3f8cc49938ae9fead8e4fc8ad19'
and c.is_deleted = '0'

先感謝您

嘗試這個:

SQL服務器

select count([building]) over (order by building) as [bulding count],
       count([floor]) over (order by [floor],[building]) as [floor count],
       count([house]) over (order by building,[floor],[house]) as [house count],
       count([room]) over (order by building,[floor],[house],[room]) as [room count],
       count([bed]) over (order by building,[floor],[house],[room],[bed]) as [room count]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM