Re: [SQL] Lowest 2 items per

2012-06-02 Thread msi77
Thank you for reply, Oliver. I want that you'll pay attention to the learn exercises which can by made under PostgreSQL among few other DBMS: http://sql-ex.ru/exercises/index.php?act=learn 02.06.2012, 19:00, "Oliveiros" : > Nice resource, msi77. > > Thanx for sharing. > > I wasn't aware of none

Re: [SQL] Lowest 2 items per

2012-06-02 Thread Oliveiros
Nice resource, msi77. Thanx for sharing. I wasn't aware of none of these techniques, actually, so I tried to start from scratch, but I should've realized that many people in the past had the same problem as Mike and I should have googled a little instead of trying to re-invent the wheel. Anyway,

Re: [SQL] Lowest 2 items per

2012-06-02 Thread msi77
A few of approaches to solve this problem: http://sql-ex.com/help/select16.php 01.06.2012, 18:34, "Relyea, Mike" : > I need a little help putting together a query.  I have the tables listed > below and I need to return the lowest two consumables (ranked by cost > divided by yield) per printer, pe

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
> -Original Message- > From: Oliveiros d'Azevedo Cristina [mailto:oliveiros.crist...@marktest.pt] > Sent: Friday, June 01, 2012 12:59 PM > To: Relyea, Mike > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Lowest 2 items per > > * I see... > >

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Mario Dankoor > Sent: Friday, June 01, 2012 2:31 PM > To: Relyea, Mike > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Lowest 2 items per > Mike,

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Mario Dankoor
On 2012-06-01 5:44 PM, Relyea, Mike wrote: -Original Message- From: David Johnston [mailto:pol...@yahoo.com] Sent: Friday, June 01, 2012 11:13 AM To: Relyea, Mike Cc: Subject: Re: [SQL] Lowest 2 items per I would recommend using the "RANK" window function with an appropriate

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
I only made grammatical changes necessary for the query to function (adding a missing FROM, fully qualifying "SELECT Make" as " SELECT subquery2.Make", etc.) I tried changing the join type to right and left but that did not have the desired result. * I see... If we add a query with a union tha

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
> -Original Message- > From: Oliveiros d'Azevedo Cristina [mailto:oliveiros.crist...@marktest.pt] > Sent: Friday, June 01, 2012 12:28 PM > To: Relyea, Mike > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Lowest 2 items per > > Yes, you are right, now, thin

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
Oliver, I had to make a few grammatical corrections on your query to get it to run, but once I did it gave me almost correct results. It leaves out all of the printer models that only have one consumable with a cost. Some printers might have more than two black inks and some might have only one

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
> -Original Message- > From: Oliveiros d'Azevedo Cristina [mailto:oliveiros.crist...@marktest.pt] > Sent: Friday, June 01, 2012 11:21 AM > To: Oliveiros d'Azevedo Cristina; Relyea, Mike; pgsql-sql@postgresql.org > Subject: Re: [SQL] Lowest 2 items per > >

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
> -Original Message- > From: David Johnston [mailto:pol...@yahoo.com] > Sent: Friday, June 01, 2012 11:13 AM > To: Relyea, Mike > Cc: > Subject: Re: [SQL] Lowest 2 items per > > > I would recommend using the "RANK" window function with an appropri

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
2.make,subquery2. model, subquery2.color,subquery2.type,subquery1.cpp ORDER BY make, model; - Original Message - From: "Oliveiros d'Azevedo Cristina" To: "Relyea, Mike" ; Sent: Friday, June 01, 2012 3:56 PM Subject: Re: [SQL] Lowest 2 items per Hi, Mike, Can you

Re: [SQL] Lowest 2 items per

2012-06-01 Thread David Johnston
On Jun 1, 2012, at 10:34, "Relyea, Mike" wrote: > I need a little help putting together a query. I have the tables listed > below and I need to return the lowest two consumables (ranked by cost > divided by yield) per printer, per color of consumable, per type of > consumable. > > CREATE TABLE

Re: [SQL] Lowest 2 items per

2012-06-01 Thread Oliveiros d'Azevedo Cristina
- From: "Relyea, Mike" To: Sent: Friday, June 01, 2012 3:34 PM Subject: [SQL] Lowest 2 items per I need a little help putting together a query. I have the tables listed below and I need to return the lowest two consumables (ranked by cost divided by yield) per printer, per col

[SQL] Lowest 2 items per

2012-06-01 Thread Relyea, Mike
I need a little help putting together a query. I have the tables listed below and I need to return the lowest two consumables (ranked by cost divided by yield) per printer, per color of consumable, per type of consumable. CREATE TABLE printers ( printerid serial NOT NULL, make text NOT NULL,