🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.interbase.sql
2 messages
2 total messages Started by Bambang P. Wed, 27 Nov 2002 08:55
SQL Statement
#11296
Author: Bambang P.
Date: Wed, 27 Nov 2002 08:55
30 lines
1345 bytes
Hi!
I have table like below:

kd        jns
------------
A         001
A         001
A         002
B         001
B         002
B         002
C         001
D         002

and I want to group by kd  and the result like this:

kd        001    002
-------------------
A          2        1
B          1        2
C          1        -
D          -        1
-------------------

Can anyone help me with this query?

--

Thanks
Bambang P.
Re: SQL Statement
#11302
Author: Bj�rge S�ther
Date: Wed, 27 Nov 2002 10:01
63 lines
2202 bytes
"Bambang P." <benkbenk@bozz.com> skrev i melding
news:3de4886d@newsgroups.borland.com...
> Hi!
> I have table like below:
>
> kd        jns
> ------------
> A         001
> A         001
> A         002
> B         001
> B         002
> B         002
> C         001
> D         002
>
> and I want to group by kd  and the result like this:
>
> kd        001    002
> -------------------
> A          2        1
> B          1        2
> C          1        -
> D          -        1
> -------------------
>
> Can anyone help me with this query?

No, what you may get is this:

kd        jns    count
-------------------
A        001   2
A        002   1
B        001   1
B        002   2
C        001   1
D        002   1
-------------------

..by issuing this call:

SELECT
  KD,
  JNS,
  COUNT(*)
FROM
  JNS_TABLE
GROUP BY
  KD, JNS

You can't write a simple SQL stmt that will return a variant number of
fields. Array fields may be a soulution, of course.
An application may create an SQL stmt or a view in code based on the results
of a query.

BTW, This functionality is available in report generators or database
components, it's called a "pivot table", "decision cube" or "crosstab", I
believe.

--
Bj�rge S�ther
bjorge@hahaha_itte.no
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads