Good time.

In the table, the following numerical values:

33.33 33 

Is there such a SQL data format where a query of the form:

 SELECT WHERE 33.33 

will output both 33.33 and 33? Something like auto-rounding up the whole.

DECISION:

 SELECT * FROM t WHERE t=33.33 OR t=FLOOR(33.33) 

Thank.

  • 2
    and why the condition not to make TRUNCATE (x, 0) = TRUNCATE (33.33,0)? or ROUND () if in the near side. - Batanichek
  • well, you can add an additional OR and round the value via ROUND (), but for some reason it seemed to me that there is exactly a data format that auto-selects integers when entering numbers with a dot. - Alexey Maksimenko
  • one
    In SQL, there is no such thing, and I note that there is no such thing anywhere in programming. Either the value is automatically rounded, if the data type is compared, the integer and then only integer values ​​are searched for, or it is not rounded and is taken as it is. - Mike
  • decided so SELECT * FROM t WHERE t = 33.33 OR t = FLOOR (33.33) - Alexey Maksimenko
  • Make your decision back and accept it as correct. - edem

1 answer 1

Will help the use of EXISTS

 SELECT * FROM table t WHERE t.column <> TRUNC(t.column) OR NOT EXISTS (SELECT 1 FROM table t2 WHERE t2.column <> TRUNC(t2.column)) 

Now more.

t.column <> TRUNC (t.column) - trunc drops the fractional part in the number. In this case, we check that the number is not an integer.

NOT EXISTS - checking for the presence of fractional values ​​in the table. If there are none, then we return all records from the table.

  • What a strange query that returns: all fractional numbers, or if there are no fractional numbers, then all numbers. - Batanichek
  • 2
    Maybe I did not understand the problem correctly. But in the header of the request it is just stated: select the numbers with a dot, if there are no such numbers, then integers. - Okdel
  • In the explanation there is an indication that I want to round up to the whole. - Alexey Maximenko
  • So still not understood. Is to blame. I just pulled explanations to the question, but in this case it was necessary to do the opposite. - Okdel