Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkaCM-00023n-Ql for pgsql-sql@arkaria.postgresql.org; Wed, 23 Aug 2017 18:16:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dkaCM-0004Ru-DS for pgsql-sql@arkaria.postgresql.org; Wed, 23 Aug 2017 18:16:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dkaCL-0004Rk-Po for pgsql-sql@postgresql.org; Wed, 23 Aug 2017 18:16:13 +0000 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dkaCE-0006Sf-4Y for pgsql-sql@postgresql.org; Wed, 23 Aug 2017 18:16:11 +0000 Received: by mail-pg0-x22c.google.com with SMTP id u191so3124257pgc.2 for ; Wed, 23 Aug 2017 11:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=mAiCfkH9yShSc5sUM8f7dMTKI1vZH1WRHePObrsr6T4=; b=KQI3MEQpNtIbqkabGi6cOo6UG5qheoHr9Y+Y50SWYfhDQxTwwssYqf0T8tPBtCJ4Lp 9sW5IJCLfWrosGyxdmvmxfEsMsmiZQ3+xccf9aDz2UuYhcjQWLevpvmrBKUe6vjTey/U B2iBNc5Bx/OdyOXiXoHp8P+pGUFz2BAsPrVZlDyLzmdtv+jCLrsYNFsB2lhaWQkAvgrB 8WxPbGKc0uH8ILmXoH9Ec9omTP56ms/AwiihEtT9z9CjOU7SgweA63ssKrrrRWmoFoLe GtMafOFbOtyJLyD9oGF5yKXDQWWeaDuaLTyWAnCgLTmOGWwKLKyxP0CACSSLMWFvBK2Q YiQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=mAiCfkH9yShSc5sUM8f7dMTKI1vZH1WRHePObrsr6T4=; b=tcBNSxD/NzQTV528ARRCPV7F1eDia1KOXZknbDGVXIm3Nrm0d5AIIBQAdrtu/KxSoQ GbpfC6RYqJ3vrKERMKzIYCZMY+hliDe85QxqcqRo4NbYMA5vfKFtwaaaZtD9q6XIXHtK 1wYEp0ayKYf+hd4dCh0lgZ9wXk35RMCDtuoCDfC1dHH5XZL8PbRBn/Dw9RMfJyyl+lCN jgvFJdkEXQ/2AJYhvkUrO5A477LKSnRkurKofS3sYJcPqi+0jIwZqzgc57AOLDmcr+DZ Yo62HRdKGXEKpA+zO6Z4Odu/6DzFw8rz4r50lLiPSL1kZr5Ndog+SYZbYJ1zo4SzwYwt 6/4A== X-Gm-Message-State: AHYfb5g7yFZZ/SCURtMQFafn7M2imz3FirjsahDhbAzvhF/1AyPicLdV vh2MlgUzSty2s5rvxYs= X-Received: by 10.84.231.200 with SMTP id g8mr3932128pln.21.1503512163967; Wed, 23 Aug 2017 11:16:03 -0700 (PDT) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id z86sm3861565pff.160.2017.08.23.11.16.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 11:16:02 -0700 (PDT) Subject: Re: how many times To: pgsql-sql@postgresql.org References: From: Rob Sargent Message-ID: <864a1386-2c98-5060-1a72-d663671af917@gmail.com> Date: Wed, 23 Aug 2017 12:15:52 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------F0A2FC490E4AC2746919943B" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------F0A2FC490E4AC2746919943B Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit On 08/23/2017 12:03 PM, Campbell, Lance wrote: > > I am not for sure how to do the below. I was hoping someone could > share their thoughts. > > Assume I have a table called T1. It contains a single filed called > “viewed” that is of type timestamp. > > Every time someone views a particular web page we insert the current > timestamp into T1. > > Now I need to ask this business question: > > On average in any consecutive five minute time frame how many times is > the web page viewed? > > Thanks, > > Lance > window functions are your friends https://www.postgresql.org/docs/current/static/functions-window.html --------------F0A2FC490E4AC2746919943B Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit



On 08/23/2017 12:03 PM, Campbell, Lance wrote:

I am not for sure how to do the below.  I was hoping someone could share their thoughts.

 

Assume I have a table called T1.  It contains a single filed called “viewed” that is of type timestamp.

 

Every time someone views a particular web page we insert the current timestamp into T1.

 

Now I need to ask this business question:

 

On average in any consecutive five minute time frame how many times is the web page viewed?

 

Thanks,

 

Lance

window functions are your friends
https://www.postgresql.org/docs/current/static/functions-window.html
--------------F0A2FC490E4AC2746919943B--