Re: Tabelle umgruppieren ?

"Gunnar \"Nick\" Bluth" <[email protected]> Sun, 27 Oct 2019 13:16:23 +0100
Newsgroups gmane.comp.db.postgresql.german
Message-ID <[email protected]>
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--ogr2Vu5gsVwWMQVeGYCHrZVeWhcpScud0
Content-Type: multipart/mixed; boundary="PGNHRKAF0CBPvntvdFJmkqr7McekwVP5h";
 protected-headers="v1"
From: "Gunnar \"Nick\" Bluth" <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
Subject: Re: Tabelle umgruppieren ?
References: <[email protected]>
In-Reply-To: <[email protected]>

--PGNHRKAF0CBPvntvdFJmkqr7McekwVP5h
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Am 27.10.2019 um 13:09 schrieb Nicola Tiling:
> Moin allerseits,
>=20
> ich bekomme eine Abfrage nicht hin. =E2=80=9ECrosstab=E2=80=9C ist daf=C3=
=BCr untauglich

Das dient ja auch zum "pivotieren"... hier brauchst du einen schlichten
self-join.

> Ich habe hier einen view f=C3=BCr eine Netzwerkdoku, mit dem Inhalt =E2=
=80=9ESwitchname", =E2=80=9EPortnummer", =E2=80=9EKabelnummer"
>=20
>=20
> switch 	    port_nr kabel_nr
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> cisco1		4	12
> cisco1		5	13
> cisco1		6	14
> cisco2		6	14
> cisco2		48	10
> juniper1	8	12
> juniper1	9	13
> juniper1	42	10
>=20
>=20
> ich h=C3=A4tte gerne dieses Ergebnis das quasi einen *Kabelweg von swit=
ch_A und port zu switch_B und port abbildet*.
> Eine kabelnummer soll/kann logischerweise  genau 2x in der Abfrage vork=
ommen weil ein Kabel auf je einen Port von zwei Switchen geht
>=20
> kabel_nr 	switch_a    port_nr_a 		switch_b 	port_nr_b
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> 10		cisco2		48		juniper1	42
> 12		cisco1		4		juniper1	8
> 13		cisco1		5		juniper1	9
> 14		cisco1		6		cisco2		6

SELECT DISTINCT ON (a.kabel_nr ORDER BY a.switch)
 	 a.kabel_nr
	,a.switch AS switch_a
	,a.port_nr AS port_nr_a
	,b.switch AS switch_b
	,b.port_nr AS port_nr_b
FROM netzwerkdoku a
JOIN netzwerkdoku b
ON a.kabel_nr =3D b.kabel_nr;

sollte m.E. dein gew=C3=BCnschtes Ergebnis liefern.

> Hat jmd. vielleicht eine z=C3=BCndende Idee - ich komm nicht so richtig=
 weiter ...
>=20
> Sch=C3=B6ne Gr=C3=BC=C3=9Fe
> Nicola
>=20

Gru=C3=9F & sch=C3=B6nes Wochenende!
--=20
Gunnar "Nick" Bluth
Gesch=C3=A4ftsf=C3=BChrer

Pro Open GmbH
Eimermacherweg 106
D-48159 M=C3=BCnster

HRB 18122, AG MS

Mobil +49 172 8853339
Email: [email protected]
_________________________________________________________________________=
_
"Ceterum censeo SystemD esse delendam" - Cato


--PGNHRKAF0CBPvntvdFJmkqr7McekwVP5h--

--ogr2Vu5gsVwWMQVeGYCHrZVeWhcpScud0
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEalk3A/SRAkpwy/bgEBCuazKJM4wFAl21ipcACgkQEBCuazKJ
M4zSiwf/cFWkkl87E4Li0gzVY1Z1sijWHs2VGgf6I/ECQmxLhXpAKvXLm5lZ/RNy
emSSR37K0eb3EvcGG24gtXMLwxSQG9mXnm5pZt9xGykfsmU9eEf+MT5I3uyrJB6n
jLfCNk5VshXQnWMNZVEieGk0iR58PzQrqaDURkHMTzlf90gDSRLyNsvhuV/rECbZ
iOlNovZ2rjoT1RqYsGRJWOOYQwcaC8GZn9R5Nqv9vEBOcejjyT8Tv5DJsiTPiUcx
OM9MciG5QpggX+EYaTu5QoI4tPIknfij3QKx/EEt+/FC86oxlCxW35FDyLqSSqag
yBogtYxttOOpsHVFOdK2+0Nx8Hq1BA==
=kNiv
-----END PGP SIGNATURE-----

--ogr2Vu5gsVwWMQVeGYCHrZVeWhcpScud0--