X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9788BD863C for ; Thu, 13 Oct 2005 09:50:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87332-01 for ; Thu, 13 Oct 2005 12:50:48 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id C8180D8517 for ; Thu, 13 Oct 2005 09:50:49 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 3444631059; Thu, 13 Oct 2005 14:50:53 +0200 (MET DST) From: djzanky@gmail.com X-Newsgroups: pgsql.sql Subject: Query information needed Date: 13 Oct 2005 05:50:46 -0700 Organization: http://groups.google.com Lines: 37 Message-ID: <1129207846.673463.305670@g44g2000cwa.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; it-it) AppleWebKit/412.7 (KHTML, like Gecko) Safari/412.5,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=81.208.106.72; posting-account=1486sAwAAAALjKW5pJT4fAdv4iBntim- To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.178 required=5 tests=[NO_REAL_NAME=0.178] X-Spam-Level: X-Archive-Number: 200510/193 X-Sequence-Number: 23046 Dear all, I have a table created with this specifications: CREATE TABLE cdr ( calldate timestamp with time zone NOT NULL default now(), clid varchar(80) NOT NULL default '', src varchar(80) NOT NULL default '', dst varchar(80) NOT NULL default '', dcontext varchar(80) NOT NULL default '', channel varchar(80) NOT NULL default '', dstchannel varchar(80) NOT NULL default '', lastapp varchar(80) NOT NULL default '', lastdata varchar(80) NOT NULL default '', duration bigint NOT NULL default '0', billsec bigint NOT NULL default '0', disposition varchar(45) NOT NULL default '', amaflags bigint NOT NULL default '0', accountcode varchar(20) NOT NULL default '', uniqueid varchar(32) NOT NULL default '', userfield varchar(255) NOT NULL default '' ); I want to extract the number of calls placed in 1 hour and the average call duration I'm working with this query: SELECT date_trunc('hour',calldate), duration FROM cdr WHERE src=601 ORDER BY calldate; i tried several other queries but i'm not able to count the number of calls in an hour (better in a time interval) and calculate the average duration. Any suggestions would be appreciated! Tnx