From: | msi77 <msi77(at)yandex(dot)ru> |
---|---|
To: | "Ozer, Pam" <pozer(at)automotive(dot)com>,pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Getting top 2 by Category |
Date: | 2011-01-11 20:00:55 |
Message-ID: | 143611294776056@web61.yandex.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
There some ways to do this in one query. Look here:
http://www.sql-ex.ru/help/select16.php
---------------
11.01.11, 22:00, "Ozer, Pam" <pozer(at)automotive(dot)com>:> This is probably very simple but I am drawing a blank. Do I need to create a cursor to iterate through a table to grab the top 2 magazines per category? Here is my table and some data . The results I need are at the bottom. Any help would be greatly appreciated: CREATE TABLE magazinecategory( magazinecategoryid smallint NOT NULL , magazineid smallint, categoryid smallint); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (1, 2, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (2, 8, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (3 9, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (4, 10, 4); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (5, 11, 4); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (6, 12,4); The results I want areCategoryID MagazineID3 23 84 104 11 Pam Ozer>
From | Date | Subject | |
---|---|---|---|
Next Message | Filip Rembiałkowski | 2011-01-11 20:11:05 | Re: help needs in converting db2 function in postgresql. |
Previous Message | Ozer, Pam | 2011-01-11 19:53:08 | Re: Getting top 2 by Category |