Friday, February 24, 2012

GROUP BY

Hi,
I am using C# and SQL 2005 Express and I would like to know if there is a
way to group rows by some columns in such a way that I can clearly see them
in a distinguished fashion when I look at a view or table.
This is my code below but when I try using GROUP BY it is not giving me the
desired effect that I would like?
For example, let's say I would like to group by the first 5 columns (i.e.
V1,V2,V3,V4,V5) and let's say the first 3 rows of my view or table contain
the values 1,2,3,4,5 for V1,V2,V3,V4,V5 respectively, and the next 3 rows
contain the values 1,2,3,4,6 for V1,V2,V3,V4,V5 respectively and so on. What
I would like to see when I look at my view or table, is some sort of visible
delineation or break of some sort by the grouping that I chose, so that I do
not have to do it visually myself because I have many records in my view.
See my view below with the 6 rows as an example.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
WHERE (MP <= 30)
ORDER BY V1, V2, V3, V4, V5
These are the 6 rows in my table and so as you can see the first 3 rows
would be in one group and the next 3 rows would be in another group. What I
would like to do is have to sort of way to show a distinction or highlight
between the first 3 rows and the next 3 rows.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Is it possible to have some kind of delineation or is what I am asking not
possible in SQL 2005 Express?
TIA
Roy
That sound rather like a crosstab query.
Greg Stigers, MCSA
remember to vote for the answers you like
|||Hi Greg,
I think that I am getting closer as I have tried the following code below
with some success but there still remains one thing that I would like to be
able to do.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
GROUP BY V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
When I get the output from this view below I would also like to count the
number of rows that contain V1 = 1. How would I do that?
For example, if the view returns these 6 rows grouped by V1,V2,V3,V4,V5 then
I would also like to count the number of times that V1 = 1. In this case it
would be 3 because the first group 1,2,3,4,5 appears 3 times.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Thanks
Roy
"G" <gregstigers+msnews@.spamcop.net> wrote in message
news:%23fc7L%2319FHA.3608@.TK2MSFTNGP09.phx.gbl...
> That sound rather like a crosstab query.
> --
> Greg Stigers, MCSA
> remember to vote for the answers you like
>

No comments:

Post a Comment