Re: pivoting data?

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: pivoting data?
Date: 2011-09-08 13:42:54
Message-ID: 4E68C65E.1030805@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="direction: ltr;">
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<style>body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body style="direction: ltr;"
bidimailui-detected-decoding-type="latin-charset" bgcolor="#ffffff"
text="#000000">
On 09/08/2011 03:15 PM, Joy Smith wrote:
<blockquote
cite="mid:CAJqhhiNtZKYxQjhXBAkGcXqopDghbUMB87crhoKDQ5HxgFrQaA(at)mail(dot)gmail(dot)com"
type="cite">Hello Chris, yes that does seem to be a lot cleaner -
though it does one thing that is not right -&nbsp;
<div>ie)</div>
<div>add to the previous data</div>
<div>&nbsp;insert into modvalues
(parties,baloons,color,dayofpurchase,amountpur) values<br>
&gt; ('1','big','red','1/2/2011',4);<br>
<br>
</div>
<div><br>
</div>
<div>then the output looks like:</div>
<div><br>
</div>
<div>baloons &nbsp; &nbsp; color &nbsp; &nbsp; &nbsp; &nbsp;jan first &nbsp; &nbsp; &nbsp; jan second &nbsp; &nbsp; jan
third</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; red &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; green &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 14</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blue &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;red &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4</div>
<div><br>
</div>
<div>instead of looking like this(having big red only show up once
with the new value under jan second):</div>
<div><br>
</div>
<div>
<div>baloons &nbsp; &nbsp; color &nbsp; &nbsp; &nbsp; &nbsp;jan first &nbsp; &nbsp; &nbsp; jan second &nbsp; &nbsp; jan
third</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; red &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; green &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 14</div>
<div>big &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blue &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3</div>
<div><br>
</div>
</div>
<div><br>
</div>
<div>thank you for your help and ideas</div>
</blockquote>
You'll want to group by baloons,color and probably take a sum of
each of the case statements.<br>
<br>
Sim<br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 2.9 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Yeoh 2011-09-08 14:07:20 Re: conditional insert
Previous Message Joy Smith 2011-09-08 12:15:23 Re: pivoting data?