在mysql中,round函數用於數據的四舍五入,它有兩種形式:
1、round(x,d) ,x指要處理的數,d是指保留幾位小數
這里有個值得注意的地方是,d可以是負數,這時是指定小數點左邊的d位整數位為0,同時小數位均為0;
2、round(x) ,其實就是round(x,0),也就是默認d為0;
舉例:
1、查詢: select round(1123.26723,2);
結果:1123.27
2、查詢: select round(1123.26723,1);
結果: 1123.3
3、查詢: select round(1123.26723,0);
結果:1123
4、查詢: select round(1123.26723,-1);
結果: 1120
5、查詢: select round(1123.26723,-2);
結果:1100
5、查詢: select round(1123.26723);
結果:1123
6、查詢: select round(1.56);
結果:2
7、使用round函數尋找中位數區間:
SELECT job, round(count(id)/2) as start, round((count(id)+1)/2) as end
————————————————