Is there a "big" function in db2?

I found in MYSQL and apparently other database engines that there is a “biggest” function that can be used as: the largest (1, 2, 3, 4), and it will return 4. I need it, but I need using IBM DB2. Does anyone know of such an equivalent function, even if it takes only 2 parameters?

I found somewhere that MAX should do this, but it doesn’t work ... it only works when the MAX column is selected.

If there is no such function, can anyone understand what a stored procedure might look like? (I have no experience with stored procedures, so I don't know what DB2 will be able to).

+3
source share
6 answers

Why is MAX not working for you?

select max (1,2,8,3,1,7) from sysibm.sysdummy1

gives me

    1
    ---------------
                 8

      1 record(s) selected.
+4

, MAX , , ( ). DB2 for LUW, DB2 z/OS DB2 i5/OS. DB2 , , ? MAX , "" - , , .

+4

Linux V9.1 "select max (1,2,3)..." -

SQL0440N "MAX" "FUNCTION", . SQLSTATE = 42884

, , . z/os -.

, Linux 9.5.

+2

:

  • ?

  • " SQL-" MAX (x) .

UPDATE: , # 1 , .

+1

, DB2 , , 9.1. , case.

max. :

create function importgenius.max2(x double, y double)
returns double
language sql
contains sql
deterministic
no external action
begin atomic
    if y is null or x >= y then return x;
    else return y;
    end if;
end

, . "" " " .

If you want another max function to work for character input, you will have to give it a different name.

+1
source

Please check the following query:

select * from table1 a,
(select appno as sub_appno,max(sno) as sub_maxsno from table1 group by appno) as tab2
where a.appno =tab2.sub_appno and a.sno=tab2.sub_maxsno
0
source

Source: https://habr.com/ru/post/1698688/


All Articles