T-SQL answer.
Re: Find the minimum or maximum value across several columns?
OK, you asked for ANY answer, so this should work with most dialects:
[sql]
if exists (select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'MyMinMaxTable')
drop table MyMinMaxTable
exec sp_dboption 'TelairDB', 'select into/bulkcopy', 'true'
CREATE TABLE [dbo].[MyMinMaxTable] (
[my_min] [decimal](16, 4) NULL ,
[my_max] [decimal](16, 4) NULL
) ON [PRIMARY]
GO
insert into MyMinMaxTable
select min(ord_qty), max(ord_qty)
from AA_TestTable
insert into MyMinMaxTable
select min(sitm_qty), max(sitm_qty)
from AA_TestTable
insert into MyMinMaxTable
select min(this_qty), max(this_qty)
from AA_TestTable
insert into MyMinMaxTable
select min(that_qty), max(that_qty)
from AA_TestTable
insert into MyMinMaxTable
select min(other_qty), max(other_qty)
from AA_TestTable
select min(my_min) as abs_min, max(my_max) as abs_max
from MyMinMaxTable
[/sql]
|