Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 18CFA632A64 for ; Mon, 12 Apr 2010 11:27:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 23340-08 for ; Mon, 12 Apr 2010 14:26:58 +0000 (UTC) X-Greylist: delayed 00:07:49.439836 by SQLgrey-1.7.6 Received: from forward14.mail.yandex.net (forward14.mail.yandex.net [95.108.130.92]) by mail.postgresql.org (Postfix) with ESMTP id 2C027635705 for ; Mon, 12 Apr 2010 11:27:07 -0300 (ADT) Received: from web133.yandex.ru (web133.yandex.ru [95.108.131.156]) by forward14.mail.yandex.net (Yandex) with ESMTP id 2A4E84E511FF; Mon, 12 Apr 2010 18:19:15 +0400 (MSD) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1271081955; bh=RSDbqnnzabywt4TDuEMl4IFT/KSVmVSS803vW6VkP/k=; h=From:To:Cc:In-Reply-To:References:Subject:MIME-Version:Message-Id: Date:Content-Transfer-Encoding:Content-Type; b=BJoQ4i20MB4/TZ0vKw6VV6ya/+WLyyZddAuQYwkBmFO2mNLolvxl8SMmAo66Y/K8q Ku5huRcP7MnJE4BGJ95XZokQ9G4zDEDizhY6tee6zYlPmHxY5UjKReCa/eMo1amNAr TwfKuFEqd3E33oVlm4lsiNCltjnY/4ZaXiw2XWaU= Received: from localhost (localhost.localdomain [127.0.0.1]) by web133.yandex.ru (Yandex) with ESMTP id 2812E4378070; Mon, 12 Apr 2010 18:19:15 +0400 (MSD) X-Yandex-Spam: 1 X-Yandex-Front: web133.yandex.ru X-Yandex-TimeMark: 1271081955 Received: from user-23.81.118.217.in-addr.arpa (user-23.81.118.217.in-addr.arpa [217.118.81.23]) by mail.yandex.ru with HTTP; Mon, 12 Apr 2010 18:19:14 +0400 From: msi77 To: Andreas Cc: pgsql-sql@postgresql.org In-Reply-To: <4BBE33B0.1050408@gmx.net> References: <4BBE33B0.1050408@gmx.net> Subject: Re: Howto get a group_number like row_number for groups MIME-Version: 1.0 Message-Id: <81561271081954@web133.yandex.ru> Date: Mon, 12 Apr 2010 18:19:14 +0400 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=AWL=0.001 X-Spam-Level: X-Archive-Number: 201004/42 X-Sequence-Number: 33969 Hi, dense_rank() over (order by object) % 2 > Hi > I'd like to have an alternating colorindex in the output of a query that > consecutive rows that are the same within a colum the same number. > The query generates a readable output from a log-table and a few others > that hold referenced texts. > log (log_id int, log_event_fk int, object_fk int , ts timestamp) > events (event_id int, event text) > objects (object_id int, object text, is_active bool) > the easy part :) > mind the the ordering is not primarily based on the timestamp > select log_id, event, object, ts > from log > join events on event_id = log_event_fk > join objects on object_id = object_fk > where object.is_active > order by object, ts > Now I'd need a dynamically generated column that alternates between 0 > and 1 so that I can later color the rows where object is the same. > row_number() over (order by object, ts) % 2 > or rank() over (order by object, ts) % 2 > produces the 0/1 alternation for rows > When I create a subselect for objects that adds the colorindex and join > this to the log instead of objects, I get the group-color only if I > omit the sorting on the timestamp. > When I order the outer select by object, ts the colorindex gets 0 in > every row. :( > I'd like to get something as this > 3, up, dev3, 2010-4-2 10:00, 0 > 8, down, dev3, 2010-4-2 14:00, 0 > 9, down, dev3, 2010-4-2 15:00, 0 > 1, up, dev7, 2010-4-2 09:00, 1 > 5, down, dev7, 2010-4-2 17:00, 1 > 2, up, dev11, 2010-4-2 12:00, 0 > 7, down, dev11, 2010-4-2 13:00, 0 > . > . > regards :) > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > Яндекс.Почта. Письма есть. Спама - нет. http://mail.yandex.ru/nospam/sign