我创建了一小段代码来测试我的项目的一部分.它工作但我有一些问题......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testtodel
{
class Program
{
private class BucketItems
{
private List<Item> ItemList;
private Item item;
public BucketItems()
{
//item = new Item();
ItemList = new List<Item>();
}
public void AddBucketItem(int _Start, int _End)
{
item = new Item();
item.SetItem(_Start, _End);
ItemList.Add(item);
}
public void PrintItemList()
{
for (int i = 0; i < ItemList.Count(); i++)
{
Console.WriteLine("Item: " + i.ToString() + " S: " + ItemList[i].Start.ToString() + " …Run Code Online (Sandbox Code Playgroud) 我有一个分层表,其中为每个孩子定义了一个父 id(除了父 id 为空的顶级孩子)。现在我想为选定的孩子在一行中显示每个父 ID。
我试图使用 CTE,但 CTE 正在向初始集添加额外的记录。相反,我想用父母列表更新初始集(SELECT 语句选择一些孩子)。
表示例(表 1):
ChildID ParentID
A P
P Q
Q Z
B P
C F
F M
M Q
D H
H Y
Y NULL
Z NULL
Run Code Online (Sandbox Code Playgroud)
如果初始语句将从子 ID 列表中选择 C、A、Q,则预期结果如下:
Selected Child Parent IDs
C F, M, Q, Z
A P, Q, Z
Q Z
Run Code Online (Sandbox Code Playgroud)