Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fvfnR-0000B7-01 for pgsql-general@arkaria.postgresql.org; Fri, 31 Aug 2018 09:32:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fvfnO-0005FG-80 for pgsql-general@arkaria.postgresql.org; Fri, 31 Aug 2018 09:32:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fvfnN-0005F9-JB for pgsql-general@lists.postgresql.org; Fri, 31 Aug 2018 09:32:50 +0000 Received: from sonic301-37.consmr.mail.ne1.yahoo.com ([66.163.184.206]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fvfnF-0002At-Hp for pgsql-general@postgresql.org; Fri, 31 Aug 2018 09:32:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1535707958; bh=zspiiAkbJP1gepBYB6AmK1eqFs8kqo20h40Qrkbf8B0=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=huAVDFnLENEA6i6z4ZnK0ZAQmlOaR5udf0v5vxRjpiGmoVai+h9BuyaAz+7bWDmDv8RsXmPLIkEGOgjvro0gJ5wCtNmTkhbVjLt4Zrwe586HI0lf3AcUC+rjRSWCskkskVB+U0kHbMi0Pz1/98GSb0kkk0D6MgpWOwV/vQcyK6OzaNaBti+r+ZCziVTjL4XEX2nLudtr74XdnGjTZI7lZEZ5hym6rA+zqVrBJMluouey3M4dZ5G8+EMNGxkvniktpPkelbNQsxclqLMmXe4XN7dxboP8tpAjRv7XbXfO7+1bYX58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0dUlhD2kig-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Fri, 31 Aug 2018 09:32:38 +0000 Date: Fri, 31 Aug 2018 09:31:55 +0000 (UTC) From: Brent Wood Reply-To: Brent Wood To: a <372660931@qq.com>, pgsql-general , "372660931@qq.com" <372660931@qq.com> Message-ID: <1318288365.1390440.1535707915942@mail.yahoo.com> In-Reply-To: References: Subject: Re: Ways to deal with large amount of columns; MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1390439_1827445590.1535707915940" X-Mailer: WebService/1.1.12337 YahooMailNeo Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0 Content-Length: 7892 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1390439_1827445590.1535707915940 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable You need to normalise your data model... the basic dataset you describe wil= l probably fit in one table with three columns, but that might be simplisti= c... All your aggregate queries are pretty basic SQL statements, which could be = represented as views or made simpler to invoke by turning them into functio= ns. So, one table describing agents, with columns for agent, date and projected= cashflow will store all your data... (index agent & date for performance) eg: for a summary for all agents for the last 12 months: select agent, sum(cashflow)=20 from tablewhere date >=3D now() - interval '1 year'group by agentorder by a= gent; or a cashflow aggregate summary for the latest month select sum(cashflow), avg(cashflow), min(cashflow), max(cashflow)=C2=A0=20 from table=20 where date =3D (select max(date) from table); or get the agent with highest projected cashflow for the latest month select agentfrom tablewhere date =3D (select max(date) from table)=C2=A0 an= d cashflow=3D(select max(cashflow) from table=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 where date =3D (select max(date) from table)= ); From: a <372660931@qq.com> To: pgsql-general =20 Sent: Thursday, August 30, 2018 9:14 PM Subject: Ways to deal with large amount of columns; =20 Hi all: I need to make a table contains projected monthly cashflow for multiple age= nts (10,000 around). Therefore, the column number would be 1000+.=C2=A0 I would need to perform simple aggregate function such as count, sum or ave= rage on each cashflow projected. So if there is anyway of doing this? Will there be anything like define a m= acro in C that I can manipulate multiple columns by simple word that repres= enting them. Thanks so much! Shore =20 ------=_Part_1390439_1827445590.1535707915940 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
You need to normalise your data model... the basic dataset you des= cribe will probably fit in one table with three columns, but that might be = simplistic...

All your aggregate queries are pretty basic SQL sta= tements, which could be represented as views or made simpler to invoke by t= urning them into functions.

<= br>
So, = one table describing agents, with columns for agent, date and projected cas= hflow will store all your data...
(index agent & date for performance)

eg: for a summary for all agents for the last 12 months:

<= div dir=3D"ltr" id=3D"yui_3_16_0_ym19_1_1535687971748_44117">select agent, = sum(cashflow)
from table
where date >=3D now() - interval '1 year'
group by agent
order by agent;

<= /div>
or a cas= hflow aggregate summary for the latest month

select sum(cashflow), avg(cashflow), min(= cashflow), max(cashflow) 
from table
where date =3D (select max(date) from t= able);

= or get the agent with highest projected cashflow for the latest month
=

select agent
from table<= /div>
where da= te =3D (select max(date) from table)
  and cashf= low=3D(select max(cashflow) from table
      where da= te =3D (select max(date) from table));


<= div style=3D"font-family: verdana, helvetica, sans-serif; font-size: 16px;"= id=3D"yui_3_16_0_ym19_1_1535687971748_43850">

From: a <372660931@qq.com>
To: pgsql-general <pgsql-general@postgresql.org= >
Sent: Thursday, = August 30, 2018 9:14 PM
Subject:<= /span> Ways to deal with large amount of columns;
<= br>
Hi all:

I need to make a table = contains projected monthly cashflow for multiple agents (10,000 around).

Therefore, the column number would be= 1000+. 

I would need to perfo= rm simple aggregate function such as count, sum or average on each cashflow= projected.

So if there is anyway o= f doing this? Will there be anything like define a macro in C that I can ma= nipulate multiple columns by simple word that representing them.

Thanks so much!

Shore


<= /div>
------=_Part_1390439_1827445590.1535707915940--