Friday, March 9, 2012

group by problem

Hi,
I have a simple question to ask(I think). I have a database which has two
columns
Number1, Number2
13044 12789
13044 18872
13044 22767
Now I need a query that gives me one row from the table. Like this:
Column1 Column2 Column3 column4
13044 12789 18872 22767
Can you help me? Thanks!
select top 1 * from <table>
or
set rowcount 1
select * from <table>
Aleksandar Grbic
MCDBA
"jesper" wrote:

> Hi,
> I have a simple question to ask(I think). I have a database which has two
> columns
> Number1, Number2
> 13044 12789
> 13044 18872
> 13044 22767
> Now I need a query that gives me one row from the table. Like this:
> Column1 Column2 Column3 column4
> 13044 12789 18872 22767
> Can you help me? Thanks!
>
|||wrong answer
"Aleksandar Grbic" wrote:
[vbcol=seagreen]
> select top 1 * from <table>
> or
> set rowcount 1
> select * from <table>
> --
> Aleksandar Grbic
> MCDBA
>
> "jesper" wrote:
|||Hello,
sorry my mistake, it wasn't so simple as I asked. The table has over 5000
rows and it looks like:
13044 12789
13044 18872
13044 22767
12004 45333
12004
12004 43992
and the result should be 13044 12789 18872 22767
12004 45333 43992
etc.
"Aleksandar Grbic" wrote:
[vbcol=seagreen]
> select top 1 * from <table>
> or
> set rowcount 1
> select * from <table>
> --
> Aleksandar Grbic
> MCDBA
>
> "jesper" wrote:
|||"jesper" wrote:
[vbcol=seagreen]
> Hello,
> sorry my mistake, it wasn't so simple as I asked. The table has over 5000
> rows and it looks like:
> 13044 12789
> 13044 18872
> 13044 22767
> 12004 45333
> 12004
> 12004 43992
> and the result should be 13044 12789 18872 22767
> 12004 45333 43992
> etc.
> "Aleksandar Grbic" wrote:
Hi,
It looks to me like you are trying to "pivot" your result set. This is also
known as a CROSSTAB query.
Please see the link below, it may be something you can modify to suit your
purposes.
http://www.stephenforte.net/owdasblo...5-15d6d813eeb8
Cheers,
Ian

No comments:

Post a Comment