单个记录中的多行

时间:2017-12-06 14:46:15

标签: sql postgresql

让我说,例如,如果我做SELECT * FROM X我得到

A1, A2, A3, A4, A5, A6, A7

是否可以进行每条记录返回的查询

A1, A2, A3    
A1, A2, A4
A1, A2, A5
A1, A2, A6
A1, A2, A7 

????

我的实际问题(这只是附加信息,不是回答问题所必需的) - >我有一个关于足球比赛的数据库,所以我有球员等,但表匹配是这样的:

homeplayer1 (fk)
homeplayer2 (fk)
.
.
.
homeplayerN (fk)
对于客场球员来说同样如此,但是我正在开发一个多维数据库实现,每个比赛只需要一个玩家关联,所以每场比赛有22个记录来适应22个玩家。

我正在使用postgresql。

2 个答案:

答案 0 :(得分:2)

    if (e.Key == Key.Enter)
    {
        var tb = sender as TextBox;

        //  Don't create this
        //Product products = new Product();

        string filter = "";//performing some ifelse to create filter
        ViewModel.GetProducts(filter);

    }
    else if (e.Key == Key.Escape)
    {
        //  Setting the DataContext to null breaks everything. Never do that. 
        //ProductsGrid.DataContext = null;

        //  Instead, just clear the collection. It's an ObservableCollection so it will 
        //  notify the DataGrid that it was cleared. 
        ViewModel.Products.Clear();

        foreach (TextBox tb in FindVisualChildren<TextBox>(this))
        {
            // do something with tb here
            tb.Text = "";
        }
    }

sqlfiddle.com

上进行测试

答案 1 :(得分:1)

我们假设某些列定义了排序;我称之为ord

with t as (
      select x.*, row_number() over (order by ord) as seqnum
      from x
     )
select t1.col, t2.col, t3.col
from t t1 join
     t t2
     on t1.seqnum = 1 and t2.seqnum = 2 join
     t t3
     on t3.seqnum > 2;

您可能想要询问有关您实际问题的其他问题,这与您在此问题中提出的问题略有不同。