<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - problem z widokiem]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=633&amp;type=atom"/>
	<updated>2011-09-05T19:06:05Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=633</id>
		<entry>
			<title type="html"><![CDATA[Odp: problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2690#p2690"/>
			<content type="html"><![CDATA[Jaka wersja Postgresql i jaki komunikat się pokazuje. U mnie na 8.4.7 na Debianie działa.
Do tego mała poprawka row_number() numeruje po kolei, a jeżeli są miejsca z taka samą ilością punktów to powinny mieć taki sam numer dlatego dołożyłem dense_rank
[url]http://www.postgresql.org/docs/current/static/functions-window.html#FUNCTIONS-WINDOW-TABLE[/url]

SELECT row_number() over (order by sum(ranking.punkty) desc)  as miejsce_a,
dense_rank() over (order by sum(ranking.punkty) desc) as miejsce_b,
sum(ranking.punkty) AS pun, ranking.nazwa
   FROM ranking
  GROUP BY ranking.nazwa order by sum(ranking.punkty) desc;


miejsce_a   miejsce_b    suma      nazwa
1                    1                9            n1
2                     2               8            n5
3                     2               8            n3
4                     3                6           n12
5                    4                4            n32
6                    4                4           n22
7                     5               1           n43]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2011-09-05T19:06:05Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2690#p2690</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2689#p2689"/>
			<content type="html"><![CDATA[w ogóle nie chce przejść przez system]]></content>
			<author>
				<name><![CDATA[lulek]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1272</uri>
			</author>
			<updated>2011-09-05T14:04:30Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2689#p2689</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2688#p2688"/>
			<content type="html"><![CDATA[Nie działa tak jak byś chciał, czy nie działa w ogóle??]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2011-09-05T10:25:40Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2688#p2688</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2687#p2687"/>
			<content type="html"><![CDATA[[quote=adamleon]Może coś takiego

SELECT row_number() over (order by sum(ranking.punkty)) as miejsce ,sum(ranking.punkty) AS pun, ranking.nazwa
   FROM ranking
  GROUP BY ranking.nazwa order by sum(ranking.punkty);[/quote]

niestety nie dziala]]></content>
			<author>
				<name><![CDATA[lulek]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1272</uri>
			</author>
			<updated>2011-09-05T09:28:48Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2687#p2687</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2686#p2686"/>
			<content type="html"><![CDATA[Może coś takiego

SELECT row_number() over (order by sum(ranking.punkty)) as miejsce ,sum(ranking.punkty) AS pun, ranking.nazwa
   FROM ranking
  GROUP BY ranking.nazwa order by sum(ranking.punkty);]]></content>
			<author>
				<name><![CDATA[adamleon]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=873</uri>
			</author>
			<updated>2011-09-05T08:31:31Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2686#p2686</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[problem z widokiem]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=2685#p2685"/>
			<content type="html"><![CDATA[Witam, dopiero od niedawna uczę się postgresql. Mam problem z dorobieniem kolumny numerującej do widoku.

 SELECT sum(ranking.punkty) AS pun, ranking.nazwa
   FROM ranking
  GROUP BY ranking.nazwa;

Widok pobiera dane z dwóch tabel: zawodnicy oraz punkty. Ma na celu na podstawie punktów stworzyć ranking graczy.
 Zapytanie:
SELECT nazwa, pun FROM ranks ORDER BY pun DESC    tworzy mi ranking.
Wszystko działa tylko nie mam pomysłu w jaki sposób mogę stworzyć kolumnę, która ponumeruje mi odpowiednie miejsca rankingu.
Proszę o podpowiedzi, pozdrawiam]]></content>
			<author>
				<name><![CDATA[lulek]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1272</uri>
			</author>
			<updated>2011-09-05T07:27:31Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=2685#p2685</id>
		</entry>
</feed>
