× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 2/9/11 5:54 AM, David FOXWELL wrote:

I need to scan this table and get the lines having the lowest value
for n1 or n2

id n1 n2
c1 4 0
c1 3 4
c1 4 5
c1 5 6

If n2 is not 0, I ignore the value of n1.

So in this example I should return 2 lines containing 4 :

c1 4 0
c1 3 4


FWiW, my [mis]interpretation given both the limited amount of logic requirements for selection and grouping [e.g. no statement of whether the value for the ID column defines a group against which the logic applies or perhaps a specific or just any possible value], and the small number\variety of row data as examples to be selected or omitted [plus optionally explaining why, in support of the given logic]:

create table inn ( id char(2), n1 decimal(2, 0), n2 decimal(2, 0) )
;
insert into inn values
('c1', 4, 0), ('c1', 3, 4), ('c1', 4, 5), ('c1', 5, 6)
;
select * from inn
where n1=(select min(n1) from inn where n2<>0)
/* lowest N1, ignoring any N1 where N2<>0 */
or n2=(select min(n2) from inn)
/* lowest N2 irrespective of the value of N1 */
;

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.