복붙노트

[SQL] SQLite는 진짜를 INT로 변환

SQL

SQLite는 진짜를 INT로 변환

SQLite는 반환 정수 값 부문

sqlite> select totalUsers/totalBids from 
(select (select count(*) from Bids) as totalBids , 
(select count(*) from Users) as totalUsers) A;
1

우리는 분할 결과의 진정한 가치를 얻을 수있는 결과를 캐스트 할 수 있습니까?

해결법

  1. ==============================

    1.1.0 숫자 그냥 곱셈 하나

    1.0 숫자 그냥 곱셈 하나

    SELECT something*1.0/total FROM somewhere
    

    즉, 부동 소수점 나누기 대신 정수 나눗셈을 줄 것이다.

  2. ==============================

    2.SQLite는의 또 다른 정수로 정수의 사업부는 것입니다 가장 가까운 정수로 항상 내림.을

    SQLite는의 또 다른 정수로 정수의 사업부는 것입니다 가장 가까운 정수로 항상 내림.을

    따라서 경우에 당신은 플로트에 열거 캐스트 :

    SELECT CAST(field1 AS FLOAT) / field2
    
  3. ==============================

    3.

    select cast ( ( select 1 ) as real );
    

    https://www.sqlite.org/lang_expr.html#castexpr

  4. ==============================

    4.또는 텍스트 열을 기반으로 열을 업데이트하려는 경우 :

    또는 텍스트 열을 기반으로 열을 업데이트하려는 경우 :

    UPDATE table_with_fields SET real_field=cast(field_with_txt AS real)
    
  5. from https://stackoverflow.com/questions/8305613/converting-int-to-real-in-sqlite by cc-by-sa and MIT license