X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A2A42D1B4F8 for ; Mon, 20 Oct 2003 11:00:10 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 95760-07 for ; Mon, 20 Oct 2003 07:59:42 -0300 (ADT) Received: from mailhub1.sghms.ac.uk (firewall.sghms.ac.uk [194.82.50.2]) by svr1.postgresql.org (Postfix) with ESMTP id 12CF9D1B4E3 for ; Mon, 20 Oct 2003 07:59:35 -0300 (ADT) Received: from [194.82.51.24] (helo=imail) by mailhub1.sghms.ac.uk with esmtp (Exim 4.24) id 1ABXkt-0005OV-Kr for pgsql-sql@postgresql.org; Mon, 20 Oct 2003 11:59:19 +0100 Received: from [172.16.20.3] (mrc1-003.sghms.ac.uk [172.16.20.3]) by imail.sghms.ac.uk (iPlanet Messaging Server 5.1 HotFix 0.7 (built May 7 2002)) with ESMTPA id <0HN100GKGYIUBN@imail.sghms.ac.uk> for pgsql-sql@postgresql.org; Mon, 20 Oct 2003 11:59:19 +0100 (BST) Date: Mon, 20 Oct 2003 11:58:00 +0100 From: Adam Witney Subject: query or design question To: pgsql-sql Message-id: MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT User-Agent: Microsoft-Entourage/10.1.1.2418 X-MailScanner-Information: Please contact sysadmin at sghms.ac.uk for more information X-MailScanner-MH1: Found to be clean X-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.9, required 5, APARENTLY_FROM_MYSELF 1.00, BAYES_00 -4.90, FROM_SGHMS -1.00) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/228 X-Sequence-Number: 15628 Hi, I have a table like so CREATE TABLE imagene ( id int bioassay_id int gene_id text s_row int s_column int s_meta_row int s_meta_column int sig_median numeric bkg_median numeric ); Rows are unique on (bioassay_id, gene_id, s_row, s_column, s_meta_row, s_meta_column) They are grouped like this (note, the counts will not always be the same) cabbage=# select bioassay_id, count(*) from imagene group by bioassay_id; bioassay_id | count -------------+------- 106 | 10944 107 | 10944 And I need to generate an output like this...... bioassay_id=106 bioassay_id=107 ---------------------- ---------------------- gene_id, sig_median, bkg_median, sig_median, bkg_median I can do something like this SELECT a.gene_id, a.sig_median, a.bkg_median, b.sig_median, b.bkg_median FROM imagene a, imagene b WHERE a.s_meta_row = b.s_meta_row AND a.s_meta_col = b.s_meta_col AND a.s_row = b.s_row AND a.s_column = b.s_column AND a.bioassay_id = 106 AND b.bioassay_id = 107; But this is quite slow... And not generic as I may need to generate the output for more than two bioassay_ids. Also I may need to do an outer join to make sure I get all rows from both data sets? I am not sure if a crosstab function will do this? Any ideas of pointers would be greatly appreciated Thanks Adam -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.