Home > Mobile >  How should I query in SQL for three metrics a, b, c and verify that they satisfy (a b)/2 = c?
How should I query in SQL for three metrics a, b, c and verify that they satisfy (a b)/2 = c?

Time:07-04

I now want to query the three indicators a, b, and c in the database, and verify whether the formula (a b) / 2 = c holds. what should I do? I can only query a, b and c now

select
    a,
    b,
    c
from
    table_test
where
    type = 1
    and
    origin not in (10, 20)

CodePudding user response:

Add the assertion in the WHERE clause:

SELECT a, b, c, IF((a   b) / 2 = c, 'True', 'False') AS result
FROM table_test
WHERE type = 1 AND origin NOT IN (10, 20) AND
      (a   b) / 2 = c;   -- added condition here
  • Related