iae...

precisei, uma vez, gerar uma consulta dessa forma... consegui fazer, mas ficou bem estatico... se o resultado da consulta for dinamico, nao é possivel fazer dessa forma....

segue a consulta...

create table a(
  id integer,
  pname varchar,
  description varchar,
  note numeric,
  weight integer);

insert into a values (3, 'Bolt', 'ACT - A', 4.5, 2);
insert into a values (3, 'Bolt', 'ACT - A', 5.0, 2);
insert into a values (3, 'Bolt', 'ACT - C', 3.0, 2);
insert into a values (3, 'Bolt', 'ACT - C', 1.0, 2);
insert into a values (3, 'Bolt', 'ACT - B', 2.0, 1);
insert into a values (3, 'Bolt', 'ACT - B', 0.5, 1);

select
    id,
    pname,
(select sum(note) from a as t where t.description = 'ACT - A') as "ACT - A", (select distinct(weight) from a as t where t.description = 'ACT - A') as weigth, (select sum(note) from a as t where t.description = 'ACT - C') as "ACT - C", (select distinct(weight) from a as t where t.description = 'ACT - C') as weigth, (select sum(note) from a as t where t.description = 'ACT - B') as "ACT - B", (select distinct(weight) from a as t where t.description = 'ACT - B') as weigth
from
    (select id,pname from a group by id,pname) as a



espero ter ajudado...


Fabio Henrique


Em 15/4/2011 09:55, Fabiano Fernandes escreveu:
Olá a todos!

Estou precisando de um empurrão para criação de um select ...

Alguem pode me ajudar?

Tenho em uma tabela da seguinte forma:


ID  |  PNAME  |  DESCRIPTION | NOTE |  WEIGHT
-----+---------------+-----------------------+----------+--------------
  3  |     Bolt     |      ACT - A       |    4.5   |     2
  3  |     Bolt     |      ACT - A       |    5.0   |     2
  3  |     Bolt     |      ACT - C       |    3.0   |     2
  3  |     Bolt     |      ACT - C       |    1.0   |     2
  3  |     Bolt     |      ACT - B       |    2.0   |     1
  3  |     Bolt     |      ACT - B       |    0.5   |     1



Preciso recuperar essas informações da seguinte forma:


ID | PNAME | ACT - A | WEIGHT | ACT - C | WEIGHT | ACT - B | WEIGHT
-----+---------------+-------------+--------------+-------------+---------------+------------+----------
3 | Bolt | 9.5 | 2 | 4.0 | 2 | 2.5 | 1


Att
Fabiano Fernandes






_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a