I
I
Ivan2017-09-07 12:32:14
SQL Server
Ivan, 2017-09-07 12:32:14

How to transpose a table to find the minimum value?

Good afternoon.
There is a table

create table #t (a int,
q int,
w int,
e int,)
insert #t values ​​(0,1,2,3)
insert #t values ​​(0,3,1,2)
insert #t values ​​(0 ,2,1,3)
insert #t values ​​(0,2,3,1)

How can I transpose it? There are references to pivot everywhere, but I can't figure out how to apply it to my table.
In general, I need to find the minimum value in a string. So I decided to transpose, use MIN() and then transpose back.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-11-14
@habrakot

DECLARE @t TABLE (a INT, q INT, w INT, e INT )
INSERT @t VALUES (0,1,2,3), (5,4,2,6), (7,1,2,8), (7,9,2,0), (0,0,1,3), (3,1,1,0)
SELECT a, q, w, e, IIF( w < e, IIF( q < w, IIF( a < q, a, q ), w ), e ) AS tMIN
  FROM @t

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question