Help to create such a sql query - List the names of languages, with the exception of those developed first or last (set using the parameter) alphabetically by the company. The database structure is as follows:

N | ТИП | ЯЗЫК | ФИРМА 

My query was the following:

 SELECT lang FROM table WHERE lang NOT IN (SELECT lang FROM table WHERE company ??? ORDER BY company ASC); 
  • 3
    Indicate what you yourself did to solve this problem and what specifically did not work out - Mike
  • Corrected, it turned out about such a request, I have no idea what to use instead ???) - blDead
  • I recall closing. you have to think, it’s rather difficult to formulate the right query right away, it’s pretty florid to turn out on an oracle - Mike
  • So I’ve been fighting for an hour, if something happens, let me know) - blDead
  • one
    Is done. I think now the answer should fully meet the conditions of the problem - Mike

3 answers 3

It turned out like that ...

 select distinct lang from test1 where lang not in (select lang from test1 t where company in( select decode(?,1,min(company),max(company)) from test1 ) ) 

If a '?' = 1 - then it will be selected besides the minimum company, another numeric value '?' - maximum

     SELECT lang FROM table WHERE lang NOT IN (SELECT decode(:param,'max',max(lang),'min',min(lang) FROM table ); 
       SELECT lang FROM table WHERE lang NOT IN ( select * from ( SELECT min(lang) FROM table where :param='min' order by company ) union all select * from ( SELECT max(lang) FROM table where :param='max' order by company ) )