9

I'm new to MySql. So I don't know many things like Casting of data types. How can I convert bool to int in MySql. And also how can I convert decimal to Int in MySql.

lulalala
  • 17,572
  • 15
  • 110
  • 169
Fasal
  • 179
  • 2
  • 2
  • 12

1 Answers1

14

Typecasting boolean to integer:

SELECT CAST(1=1 AS SIGNED INTEGER); /* 1 */

Same for decimal and strings:

SELECT CAST("1.23" AS SIGNED INTEGER); /* 1 */
BenMorel
  • 34,448
  • 50
  • 182
  • 322