This should be simple and shows my SQL ignorance:
SQL> select max(1,2) from dual; select max(1,2) from dual * ERROR at line 1: ORA-00909: invalid number of arguments
I know max is normally used for aggregates. What can I use here?
In the end, I want to use something like
select total/max(1,number_of_items) from xxx;
where number_of_items is an integer and can be 0. I want to see total also in this case.
Oracle MAX() function syntax The Oracle MAX() function is an aggregate function that returns the maximum value of a set. Similar to the MIN() function, the DISTINCT and ALL clauses are irrelevant to the MAX() function. The Oracle MAX() function also ignores NULL values.
MAX is an aggregate function that evaluates the maximum of an expression over a set of rows (see Aggregates (set functions)). MAX is allowed only on expressions that evaluate to built-in data types (including CHAR, VARCHAR, DATE, TIME, CHAR FOR BIT DATA, etc.).
The SQL MIN() and MAX() Functions The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column.
It looks like you're using Oracle so you can use the greatest
function for this in place of max
select total/greatest(1,number_of_items) from xxx;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With