<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Zliczanie rekordów w kolumnie w zależności od daty.]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=1424&amp;type=atom"/>
	<updated>2012-11-30T21:51:31Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=1424</id>
		<entry>
			<title type="html"><![CDATA[Odp: Zliczanie rekordów w kolumnie w zależności od daty.]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3812#p3812"/>
			<content type="html"><![CDATA[są dwie metody (obie obarczone pewną komplikacją, skrypt sql musi być generowany po stronie aplikacji klienckiej)

Select * From crosstab ( 'select ''ilość rekordów''::text,extract (year from data) as opis,count(id) as ilosc from tabela group by extract (year from data)','select * from generate_series ((select min(extract (year from data))::bigint from tabela),(select max(extract (year from data))::bigint from tabela))') as d ( a text,"2011" int,"2012" int);

select 
 count(case extract (year from data) when 2011 then id else null end) as ilosc_2011 
,count(case extract (year from data) when 2012 then id else null end) as ilosc_2012
from tabela;]]></content>
			<author>
				<name><![CDATA[c_michal]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=627</uri>
			</author>
			<updated>2012-11-30T21:51:31Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3812#p3812</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Zliczanie rekordów w kolumnie w zależności od daty.]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=3811#p3811"/>
			<content type="html"><![CDATA[Witam, kolejny problem:
Mam tabelę :

[code]
 id |    data
----+------------
 1  | 01-03-2012
 2  | 12-03-2012
 3  | 15-03-2011
 4  | 26-03-2012
 5  | 03-03-2011
[/code]

Jak powinna wyglądać kwerenda, która w wyniku dałaby:

[code]
 Pozycje 2011 | Pozycje 2012
--------------+--------------
 2            | 3
[/code]]]></content>
			<author>
				<name><![CDATA[lasoty]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1424</uri>
			</author>
			<updated>2012-11-30T13:44:07Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=3811#p3811</id>
		</entry>
</feed>
