Note that there are some explanatory texts on larger screens.

plurals
  1. POData grouping in SQL
    primarykey
    data
    text
    <p>I am working on a small project using C# and EF5.0 and I need to group some data. Let say I have table of columns in a building like shown below.</p> <pre><code>+----------+--------Columns Table--+------+------+ | ColumnID |ColumnName|Width|Length|Height|number| +----------+----------+-----+------+------+------+ | 1 | C101 | 50 | 70 | 250 | 1 | | 2 | C102 | 70 | 70 | 250 | 1 | | 3 | C103 | 70 | 60 | 250 | 1 | | 4 | C104 | 90 | 70 | 250 | 1 | | 5 | C105 | 40 | 50 | 250 | 1 | | 6 | C106 | 50 | 70 | 250 | 1 | | 7 | C107 | 50 | 60 | 250 | 1 | | 8 | C108 | 70 | 70 | 250 | 1 | +----------+----------+-----+------+------+------+ </code></pre> <p>I need a C# code to see the above data groupped like this:</p> <pre><code>+----------+---Groupped Columns Table-----+------+ |G_ColumnID|ColumnName|Width|Length|Height|number| +----------+----------+-----+------+------+------+ | 1 |C(101-106)| 50 | 70 | 250 | 2 | | 2 |C(102-108)| 70 | 70 | 250 | 2 | | 3 | C103 | 70 | 60 | 250 | 1 | | 4 | C104 | 90 | 70 | 250 | 1 | | 5 | C105 | 40 | 50 | 250 | 1 | | 6 | C107 | 50 | 60 | 250 | 1 | +----------+----------+-----+------+------+------+ </code></pre> <p>I prefer clues than the exact solution.</p> <p><strong>EDIT :</strong> Below code shows my current state. I think I can find the columns with the same Height, Width and Length using this code. But I am not sure how to generate a new name for the group.</p> <pre><code>using (pehlivanEntities context = new pehlivanEntities()) { foreach (var item in context.table1) { int id = item.ColumnID; foreach (var item2 in context.table1) { int id2 = item2.ColumnID; if (id != id2) { if (item.Width == item2.Width) { if (item.Length == item2.Length) { if (item.Height == item2.Height) { //Alter item.ColumnName //increase item.number by one //Remove item2 } } } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload