簡體   English   中英

使用 SQL,如何從父子關系的兩列中找到表中的子編號?

[英]Using SQL, how do you find the child number in a table from two columns where they are parent-child relationships?

在此處輸入圖像描述

從此表中,查詢后我想獲取顯示每個 id 的子編號的子列。

我想:

在此處輸入圖像描述

標量子查詢將產生您想要的數據。 例如:

select
  t.*,
  (select count(*) from t b where b.parent_id = t.id) as child
from t

暫無
暫無

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

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