sqlÖгý·¨Ôõôд
sql ³ý·¨Ê¹Óà / ÔËËã·û£¬³ýÊýΪÕûÊýʱ·µ»ØÕûÊýÉáÆúСÊý£¬ÎªÐ¡Êýʱ·µ»Ø¸¡µã±£´æСÊýλ¡£³ýÒÔ 0 »á±¨´í£¬·ûºÅ²î±ðЧ¹ûΪ¸º¡£¿ÉʹÓà round() º¯Êý±£´æÖ¸¶¨Ð¡ÊýλÊý£¬×ª»»Êý×ÖΪ¸¡µãÐÍ¿É×èÖ¹¾«¶ÈËðʧ¡£
SQL Öгý·¨
ÔõÑù¾ÙÐгý·¨£¿
SQL ÖÐʹÓà / ÔËËã·û¾ÙÐгý·¨¡£
³ýÊýΪÕûÊýʱ
ÈôÊdzýÊýΪÕûÊý£¬SQL ½«·µ»ØÒ»¸öÕûÊýЧ¹û£¬Ð¡Êý²¿·Ö½«±»ÉáÆú¡£ÀýÈ磺
SELECT 10 / 3; -- ·µ»Ø 3
µÇ¼ºó¸´ÖÆ
³ýÊýΪСÊýʱ
ÈôÊdzýÊýΪСÊý£¬SQL ½«·µ»ØÒ»¸ö¸¡µãЧ¹û£¬±£´æСÊýλ¡£ÀýÈ磺
SELECT 10 / 3.5; -- ·µ»Ø 2.857142857142857
µÇ¼ºó¸´ÖÆ
ÌØÊâÇéÐÎ
³ýÒÔ 0£º³ýÒÔ 0 »á·µ»ØÒ»¸ö¹ýʧ¡£
Ч¹ûΪ¸º£ºÈôÊDZ»³ýÊýºÍ³ýÊýµÄ·ûºÅ²î±ð£¬Ð§¹û½«Îª¸º¡£
ʹÓà ROUND() º¯Êý
Òª±£´æÌض¨Î»ÊýµÄСÊý£¬¿ÉÒÔʹÓà ROUND() º¯Êý¡£ÀýÈ磺
SELECT ROUND(10 / 3.5, 2); -- ·µ»Ø 2.86
µÇ¼ºó¸´ÖÆ
×èÖ¹¾«¶ÈËðʧ
ΪÁË×èÖ¹¾«¶ÈËðʧ£¬½¨Ò齫Êý×Öת»»Îª¸¡µãÐÍ£¬È»ºóÔÙ¾ÙÐгý·¨¡£ÀýÈ磺
SELECT CAST(10 AS FLOAT) / CAST(3.5 AS FLOAT); -- ·µ»Ø 2.857142857142857
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇsqlÖгý·¨ÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡