[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-sql
Subject:    Re: [SQL] Postgres-sql-php
From:       "Oliveiros Cristina" <oliveiros.cristina () gmail ! com>
Date:       2008-10-23 18:00:54
Message-ID: f54607780810231100v47bbd430h96ddafa7906dad02 () mail ! gmail ! com
[Download RAW message or body]

I guess you can change a little the query to your needs.
The problem is pretty much the same...
I've used c3 column in equality, but if this column
has repeated values, just choose any column or combination of columns which
is unique.

Best,
Oliveiros

SELECT a.c1,a.c2,b.c3,b.c4,a.c5,b.c6
FROM
(
SELECT c1,c2,c5, MIN(c3)as primeiraFROM t1
GROUP BY c1,c2,c5
) a
RIGHT JOIN t1 b
ON b.c3 = a.primeira
AND b.c1 = a.c1
AND a.c2 = b.c2
AND a.c5 = b.c5

2008/10/23 Zied Kharrat <khzied@gmail.com>

> Really, i have this schema:
>
> *c1     c2     c3      c4     c5      c6*
> *v1*     *v2*     v3      v4     *v5*      v6
> *v1*     *v2*     v7      v8     *v5*      v9
> *v1*     *v2*     v10    v11    *v5*      v12
>
> how can i do my sql request to obtain this?
>
> *c1     c2     c3      c4     c5      c6*
> *v1*     *v2*     v3      v4     *v5*      v6
> *            *     v7      v8     *    *      v9
> *             *     v10    v11    *   *      v12
>
>
> Thank u very much :)
>



-- 
even the biggest failure, even the worst mistake, beats the hell out of
never trying...
- Meredith Grey

[Attachment #3 (text/html)]

<br><font size="2" face="Courier New"><div class="Ih2E3d">I guess you can change a \
little the query to your needs.<br>The problem is pretty much the same...<br>I&#39;ve \
used c3 column in equality, but if this column<br>has repeated values, just choose \
any column or combination of columns which is unique.<br> \
<br>Best,<br>Oliveiros<br><br>SELECT  a.<font color="#ff0000">c1</font><span \
style="color: rgb(255, 102, 102);"></span>,a.<span style="color: rgb(255, 0, \
0);">c2</span>,b.<span style="color: rgb(255, 102, 102);">c3</span>,b.c4,<font \
color="#ff0000">a.c5,</font><font color="#000000">b.c6</font><br> \
FROM<br>(<br></div>SELECT c1,c2,c5, MIN(c3)as  primeira<div class="Ih2E3d">FROM \
t1<br>GROUP BY c1,c2,c5<br>) a<br>RIGHT JOIN t1 b<br></div>ON b.c3 =  \
a.primeira<br>AND b.c1 = a.c1<br>AND a.c2 = b.c2<br>AND a.c5 = \
b.c5<br></font><br><div class="gmail_quote">2008/10/23 Zied Kharrat <span \
dir="ltr">&lt;<a href="mailto:khzied@gmail.com">khzied@gmail.com</a>&gt;</span><br> \
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">Really, i have this \
schema:<br><br><u>c1&nbsp;&nbsp;&nbsp;&nbsp; c2 &nbsp; &nbsp; c3 &nbsp; &nbsp;&nbsp; \
c4&nbsp;&nbsp;&nbsp;&nbsp; c5 &nbsp; &nbsp;&nbsp; c6</u><br> \
<b>v1</b>&nbsp;&nbsp;&nbsp;&nbsp; <b>v2</b>&nbsp;&nbsp;&nbsp;&nbsp; \
v3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v4&nbsp;&nbsp;&nbsp;&nbsp; \
<b>v5</b>&nbsp;&nbsp;&nbsp; &nbsp; v6<br><b>v1</b>&nbsp;&nbsp;&nbsp;&nbsp; \
<b>v2</b>&nbsp;&nbsp;&nbsp;&nbsp; v7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
v8&nbsp;&nbsp;&nbsp;&nbsp; <b>v5</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v9<br> \
<b>v1</b>&nbsp;&nbsp;&nbsp;&nbsp; <b>v2</b>&nbsp;&nbsp;&nbsp;&nbsp; \
v10&nbsp;&nbsp;&nbsp; v11&nbsp;&nbsp;&nbsp; <b>v5</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
v12<br><br>how can i do my sql request to obtain \
this?<br><br><u>c1&nbsp;&nbsp;&nbsp;&nbsp; c2 &nbsp; &nbsp; c3 &nbsp; &nbsp;&nbsp; \
c4&nbsp;&nbsp;&nbsp;&nbsp; c5 &nbsp; &nbsp;&nbsp; \
c6</u><br><b>v1</b>&nbsp;&nbsp;&nbsp;&nbsp; <b>v2</b>&nbsp;&nbsp;&nbsp;&nbsp; \
v3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v4&nbsp;&nbsp;&nbsp;&nbsp; \
<b>v5</b>&nbsp;&nbsp;&nbsp; &nbsp; v6<br>

<b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</b> &nbsp;&nbsp;&nbsp; \
v7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v8&nbsp;&nbsp;&nbsp;&nbsp; <b>&nbsp; &nbsp; \
</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v9<br><b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;&nbsp;</b> &nbsp;&nbsp;&nbsp; v10&nbsp;&nbsp;&nbsp; v11&nbsp;&nbsp;&nbsp; \
<b>&nbsp; &nbsp;</b> &nbsp;&nbsp;&nbsp;&nbsp; v12<br><br><br>Thank u very much \
:)<br></div> </blockquote></div><br><br clear="all"><br>-- <br>even the biggest \
failure, even the worst mistake, beats the hell out of never trying...<br>- Meredith \
Grey<br><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic