Je veux comparer la valeur de la colonne 3 quelle valeur de comparaison de Col2 dans la table.
Col1 Col2 Col3
12 < 25 TRUE
25 > 20 TRUE
15 = 25 FALSE
SELECT (case when Col2 = '<' then Col1 < Col3 else Col1 end)
Quelqu'un peut-il m'aider ? Avancé Merci.
Vous pouvez essayer d'utiliser un case
, comme ceci:
case when Col2 = '<' then Col1 < Col3 when Col2 = '>' then Col1 > Col3 when Col2 = '=' then Col1 = Col3 end case
la requête pourrait être
select case when col2 = '=' then case when (col1 = col3) then 1 else 0 end when col2 = '>' then case when (col1 > col3) then 1 else 0 end when col2 = '<' then case when (col1 < col3) then 1 else 0 end else 0 end from MyTable
un autre est possibily
(Col2 = '<' and (Col1 < Col3)) or (Col2 = '>' and (Col1 > Col3)) or (Col2 = '=' and (Col1 = Col3))