How to use count(*) and Division Operation in SQL statements

后端 未结 2 506
栀梦
栀梦 2021-01-18 15:58

I\'m loading big data into database,

i want to know how this process going.

i use

select count(*) from table

to check how

相关标签:
2条回答
  • 2021-01-18 16:05

    Integer division returns an integer, the decimal part is truncated. You could divide by 20000.0:

    select ( count(*)/20000.0 ) from table
    

    Demo

    MSDN / (Divide)

    If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

    0 讨论(0)
  • 2021-01-18 16:14
    Select CONVERT(DECIMAL(6,4),COUNT(*)) / CONVERT(DECIMAL(6,4),20000) FROM TABLE
    

    - Its important that you match the type explicitly because not all numbers are integers and not all decimals are the same. DECIMAL(6,4) is effectively its own data type which is not the same as DECIMAL(6,3).

    0 讨论(0)
提交回复
热议问题