🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #11302

Re: SQL Statement

#11302
From: 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
Technical Details
Message-ID: <3de4988b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3de4886d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 114a0e,35312f00878810db
X-Google-Attributes: gid114a0e,public
X-Google-ArrivalTime: 2002-11-27 02:10:06 PST
From: "Bj�rge S�ther" <bjorge@hahaha_itte.no>
Newsgroups: borland.public.interbase.sql
References: <3de4886d@newsgroups.borland.com>
Subject: Re: SQL Statement
Date: Wed, 27 Nov 2002 11:01:36 +0100
Lines: 65
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 130.67.253.243
Message-ID: <3de4988b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1038391435 130.67.253.243 (27 Nov 2002 02:03:55 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail